Class Client (0.29.2)

Client(credentials=None, _http=None, client_info=None)

Client to bundle configuration needed for API requests.

See https://cloud.google.com/resource-manager/reference/rest/ for more information on this API.

Automatically get credentials::

>>> from google.cloud import resource_manager
>>> client = resource_manager.Client()

Parameters

NameDescription
credentials google.auth.credentials.Credentials

(Optional) The OAuth2 Credentials to use for this client. If not passed (and if no _http object is passed), falls back to the default inferred from the environment.

_http requests.Session

(Optional) HTTP object to make requests. Can be any object that defines request() with the same interface as requests.Session.request. If not passed, an _http object is created that is bound to the credentials for the current object. This parameter should be considered private, and could change in the future.

client_info google.api_core.client_info.ClientInfo

The client info used to send a user-agent string along with API requests. If None, then default info will be used. Generally, you only need to set this if you're developing your own library or partner tool.

Methods

fetch_project

fetch_project(project_id)

Fetch an existing project and it's relevant metadata by ID.

Parameter
NameDescription
project_id str

The ID for this project.

Returns
TypeDescription
ProjectA Project with metadata fetched from the API.

list_projects

list_projects(filter_params=None, page_size=None)

List the projects visible to this client.

Example::

>>> from google.cloud import resource_manager
>>> client = resource_manager.Client()
>>> for project in client.list_projects():
...     print(project.project_id)

List all projects with label 'environment' set to 'prod' (filtering by labels)::

>>> from google.cloud import resource_manager
>>> client = resource_manager.Client()
>>> env_filter = {'labels.environment': 'prod'}
>>> for project in client.list_projects(env_filter):
...     print(project.project_id)

See https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/list

Complete filtering example::

>>> project_filter = {  # Return projects with...
...     'name': 'My Project',  # name set to 'My Project'.
...     'id': 'my-project-id',  # id set to 'my-project-id'.
...     'labels.stage': 'prod',  # the label 'stage' set to 'prod'
...     'labels.color': '*'  # a label 'color' set to anything.
... }
>>> client.list_projects(project_filter)
Parameters
NameDescription
filter_params dict

(Optional) A dictionary of filter options where each key is a property to filter on, and each value is the (case-insensitive) value to check (or the glob * to check for existence of the property). See the example above for more details.

page_size int

(Optional) The maximum number of projects in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API.

Returns
TypeDescription
google.api_core.page_iterator.IteratorIterator of all Project. that the current user has access to.