Python

0.02.2

Datasets#

Create / interact with gcloud datastore datasets.

class gcloud.datastore.dataset.Dataset(id, connection=None)[source]#

Bases: object

A dataset in the Cloud Datastore.

This class acts as an abstraction of a single dataset in the Cloud Datastore.

A dataset is analogous to a database in relational database world, and corresponds to a single project using the Cloud Datastore.

Typically, you would only have one of these per connection however it didn’t seem right to collapse the functionality of a connection and a dataset together into a single class.

Datasets (like gcloud.datastore.query.Query) are immutable. That is, you cannot change the ID and connection references. If you need to modify the connection or ID, it’s recommended to construct a new Dataset.

Parameters:
connection()[source]#

Get the current connection.

>>> dataset = Dataset('dataset-id', connection=conn)
>>> dataset.connection()
<Connection object>
Return type:gcloud.datastore.connection.Connection
Returns:Returns the current connection.
entity(kind, exclude_from_indexes=())[source]#

Create an entity bound to this dataset.

Parameters:
Return type:

gcloud.datastore.entity.Entity

Returns:

a new Entity instance, bound to this dataset.

get_entities(keys)[source]#

Retrieves entities from the dataset, along with their attributes.

Parameters:item_name – The name of the item to retrieve.
Return type:list of gcloud.datastore.entity.Entity
Returns:The requested entities.
get_entity(key)[source]#

Retrieves entity from the dataset, along with its attributes.

Parameters:item_name – The name of the item to retrieve.
Return type:gcloud.datastore.entity.Entity or None
Returns:The requested entity, or None if there was no match found.
id()[source]#

Get the current dataset ID.

>>> dataset = Dataset('dataset-id', connection=conn)
>>> dataset.id()
'dataset-id'
Return type:string
Returns:The current dataset ID.
query(*args, **kwargs)[source]#

Create a query bound to this dataset.

Parameters:
  • args – positional arguments, passed through to the Query
  • kw – keyword arguments, passed through to the Query
Return type:

gcloud.datastore.query.Query

Returns:

a new Query instance, bound to this dataset.

transaction(*args, **kwargs)[source]#

Create a transaction bound to this dataset.

Parameters:
  • args – positional arguments, passed through to the Transaction
  • kw – keyword arguments, passed through to the Transaction
Return type:

gcloud.datastore.transaction.Transaction

Returns:

a new Transaction instance, bound to this dataset.