airflow.contrib.hooks.datastore_hook

Module Contents

class airflow.contrib.hooks.datastore_hook.DatastoreHook(datastore_conn_id='google_cloud_datastore_default', delegate_to=None)[source]

Bases:airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook

Interact with Google Cloud Datastore. This hook uses the Google Cloud Platform connection.

This object is not threads safe. If you want to make multiple requests simultaneously, you will need to create a hook per thread.

get_conn(self, version='v1')[source]

Returns a Google Cloud Datastore service object.

allocate_ids(self, partialKeys)[source]

Allocate IDs for incomplete keys. see https://cloud.google.com/datastore/docs/reference/rest/v1/projects/allocateIds

Parameters

partialKeys – a list of partial keys

Returns

a list of full keys.

begin_transaction(self)[source]

Get a new transaction handle

Returns

a transaction handle

commit(self, body)[source]

Commit a transaction, optionally creating, deleting or modifying some entities.

Parameters

body – the body of the commit request

Returns

the response body of the commit request

lookup(self, keys, read_consistency=None, transaction=None)[source]

Lookup some entities by key

Parameters
  • keys – the keys to lookup

  • read_consistency – the read consistency to use. default, strong or eventual. Cannot be used with a transaction.

  • transaction – the transaction to use, if any.

Returns

the response body of the lookup request.

rollback(self, transaction)[source]

Roll back a transaction

Parameters

transaction – the transaction to roll back

run_query(self, body)[source]

Run a query for entities.

Parameters

body – the body of the query request

Returns

the batch of query results.

get_operation(self, name)[source]

Gets the latest state of a long-running operation

Parameters

name – the name of the operation resource

delete_operation(self, name)[source]

Deletes the long-running operation

Parameters

name – the name of the operation resource

poll_operation_until_done(self, name, polling_interval_in_seconds)[source]

Poll backup operation state until it’s completed

export_to_storage_bucket(self, bucket, namespace=None, entity_filter=None, labels=None)[source]

Export entities from Cloud Datastore to Cloud Storage for backup

import_from_storage_bucket(self, bucket, file, namespace=None, entity_filter=None, labels=None)[source]

Import a backup from Cloud Storage to Cloud Datastore