google.datalab Module

class google.datalab.Context(project_id, credentials, config=None)[source]

Maintains contextual state for connecting to Cloud APIs.

Initializes an instance of a Context object.

Parameters:
  • project_id – the current cloud project.
  • credentials – the credentials to use to authorize requests.
  • config – key/value configurations for cloud operations
config

Retrieves the value of the config property.

Returns:The current config object used in cloud operations
credentials

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.
project_id

Retrieves the value of the project_id property.

Returns:The current project id to associate with API requests.
set_config(config)[source]

Set the config property for the context.

set_credentials(credentials)[source]

Set the credentials for the context.

set_project_id(project_id)[source]

Set the project_id for the context.

class google.datalab.Job(job_id=None, future=None)[source]

A manager object for async operations.

A Job can have a Future in which case it will be able to monitor its own completion state and result, or it may have no Future in which case it must be a derived class that manages this some other way. We do this instead of having an abstract base class in order to make wait_one/wait_all more efficient; instead of just sleeping and polling we can use more reactive ways of monitoring groups of Jobs.

Initializes an instance of a Job.

Parameters:
  • job_id – a unique ID for the job. If None, a UUID will be generated.
  • future – the Future associated with the Job, if any.
end_time_utc

The UTC end time of the job (or None if incomplete) as a Python datetime.

errors

Get the non-fatal errors in the job.

Returns:None if the job is still running, else the list of errors that occurred.
failed

Get the success state of the job.

Returns:True if the job failed; False if it is still running or succeeded (possibly with partial failure).
fatal_error

Get the job error.

Returns:None if the job succeeded or is still running, else the error tuple for the failure.
id

Get the Job ID.

Returns:The ID of the job.
is_complete

Get the completion state of the job.

Returns:True if the job is complete; False if it is still running.
result()[source]

Get the result for a job. This will block if the job is incomplete.

Returns:The result for the Job.
Raises:An exception if the Job resulted in an exception.
start_time_utc

The UTC start time of the job as a Python datetime.

state

Describe the state of a Job.

Returns: A string describing the job’s state.

total_time

The total time in fractional seconds that the job took, or None if not complete.

wait(timeout=None)[source]

Wait for the job to complete, or a timeout to happen.

Parameters:timeout – how long to wait before giving up (in seconds); default None which means no timeout.
Returns:The Job