Projects

Utility for managing projects via the Cloud Resource Manager API.

class google.cloud.resource_manager.project.Project(project_id, client, name=None, labels=None)

Bases: object

Projects are containers for your work on Google Cloud Platform.

NOTE: A Project can also be created via Client.new_project()

To manage labels on a Project:

>>> from google.cloud import resource_manager
>>> client = resource_manager.Client()
>>> project = client.new_project('purple-spaceship-123')
>>> project.labels = {'color': 'purple'}
>>> project.labels['environment'] = 'production'
>>> project.update()

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

  • Parameters

create(client=None)

API call: create the project via a POST request.

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

delete(client=None, reload_data=False)

API call: delete the project via a DELETE request.

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

This actually changes the status (lifecycleState) from ACTIVE to DELETE_REQUESTED. Later (it’s not specified when), the project will move into the DELETE_IN_PROGRESS state, which means the deleting has actually begun.

  • Parameters

    • client (google.cloud.resource_manager.client.Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current project.

    • reload_data (bool) – Whether to reload the project with the latest state. If you want to get the updated status, you’ll want this set to True as the DELETE method doesn’t send back the updated project. Default: False.

exists(client=None)

API call: test the existence of a project via a GET request.

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

classmethod from_api_repr(resource, client)

Factory: construct a project given its API representation.

  • Parameters

  • Return type

    google.cloud.resource_manager.project.Project

  • Returns

    The project created.

property full_name()

Fully-qualified name (ie, 'projects/purple-spaceship-123').

property path()

URL for the project (ie, '/projects/purple-spaceship-123').

reload(client=None)

API call: reload the project via a GET request.

This method will reload the newest metadata for the project. If you’ve created a new Project instance via Client.new_project(), this method will retrieve project metadata.

WARNING: This will overwrite any local changes you’ve made and not saved via update().

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

set_properties_from_api_repr(resource)

Update specific properties from its API representation.

undelete(client=None, reload_data=False)

API call: undelete the project via a POST request.

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

This actually changes the project status (lifecycleState) from DELETE_REQUESTED to ACTIVE. If the project has already reached a status of DELETE_IN_PROGRESS, this request will fail and the project cannot be restored.

  • Parameters

    • client (google.cloud.resource_manager.client.Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current project.

    • reload_data (bool) – Whether to reload the project with the latest state. If you want to get the updated status, you’ll want this set to True as the DELETE method doesn’t send back the updated project. Default: False.

update(client=None)

API call: update the project via a PUT request.

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