Python
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: - id (string) – The ID of the dataset (your project ID)
- connection (gcloud.datastore.connection.Connection) – The connection to use for executing API calls.
- 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: - kind (string) – the “kind” of the new entity (see https://cloud.google.com/datastore/docs/concepts/entities#Datastore_Kinds_and_identifiers)
- exclude_from_indexes – names of fields whose values are not to be indexed.
Return type: 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: Returns: a new Query instance, bound to this dataset.