datalab.context Module

class datalab.context.Context(project_id, credentials)[source]

Maintains contextual state for connecting to Cloud APIs.

Initializes an instance of a Context object.

  • project_id – the current cloud project.
  • credentials – the credentials to use to authorize requests.

Retrieves the value of the credentials property.

Returns:The current credentials used in authorizing API requests.
static default()[source]

Retrieves a default Context object, creating it if necessary.

The default Context is a global shared instance used every time the default context is retrieved.

Attempting to use a Context with no project_id will raise an exception, so on first use set_project_id must be called.

Returns:An initialized and shared instance of a Context object.
static is_signed_in()[source]

If the user has signed in or it is on GCE VM with default credential.


Retrieves the value of the project_id property.

Returns:The current project id to associate with API requests.

Set the credentials for the context.


Set the project_id for the context.

class datalab.context.Project(api, id, number, name)[source]

Simple wrapper class for Cloud projects.

class datalab.context.Projects(credentials=None)[source]

Iterator class for enumerating the active projects accessible to the account.

Initialize the Projects object.

Parameters:credentials – the credentials for the account.
static get_default_id(credentials=None)[source]

Get default project id.

Returns: the default project id if there is one, or None.

static save_default_id(project_id)[source]

Save default project id to config so it will persist across kernels and Datalab runs.

Parameters:project_id – the project_id to save.