googledatastore Package¶
googledatastore
Package¶
googledatastore client.
-
googledatastore.__init__.
begin_transaction
(request)[source]¶ See connection.Datastore.begin_transaction.
connection
Module¶
googledatastore connection.
-
class
googledatastore.connection.
Datastore
(dataset, credentials=None, host=None)[source]¶ Bases:
object
Datastore client connection constructor.
-
allocate_ids
(request)[source]¶ Allocate ids for incomplete keys.
- Args:
- request: AllocateIdsRequest proto message.
- Returns:
- AllocateIdsResponse proto message.
- Raises:
- RPCError: The underlying RPC call failed with an HTTP error. (See: .response attribute)
-
begin_transaction
(request)[source]¶ Begin a new transaction.
- Args:
- request: BeginTransactionRequest proto message.
- Returns:
- BeginTransactionResponse proto message.
- Raises:
- RPCError: The underlying RPC call failed with an HTTP error. (See: .response attribute)
-
commit
(request)[source]¶ Commit a mutation, transaction or mutation in a transaction.
- Args:
- request: CommitRequest proto message.
- Returns:
- CommitResponse proto message.
- Raises:
- RPCError: The underlying RPC call failed with an HTTP error. (See: .response attribute)
-
lookup
(request)[source]¶ Lookup entities by key.
- Args:
- request: LookupRequest proto message.
- Returns:
- LookupResponse proto message.
- Raises:
- RPCError: The underlying RPC call failed with an HTTP error. (See: .response attribute)
-
-
exception
googledatastore.connection.
Error
[source]¶ Bases:
exceptions.Exception
A Datastore service error occured.
-
exception
googledatastore.connection.
HTTPError
[source]¶ Bases:
googledatastore.connection.Error
An HTTP error occured.
-
response
= None¶
-
-
exception
googledatastore.connection.
RPCError
(method, response, content)[source]¶ Bases:
googledatastore.connection.HTTPError
The Datastore RPC failed.
-
method
= None¶
-
reason
= None¶
-
-
exception
googledatastore.connection.
AuthError
[source]¶ Bases:
googledatastore.connection.Error
Authentication failed.
-
exception
googledatastore.connection.
BadArgumentError
[source]¶ Bases:
googledatastore.connection.Error
Argument validation failed.
datastore_v1_pb2
Module¶
helper
Module¶
googledatastore helper.
-
googledatastore.helper.
get_credentials_from_env
()[source]¶ Get datastore credentials from the environment.
Try and fallback on the following credentials in that order: - Google APIs Signed JWT credentials based on DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE environment variables - Compute Engine service account - No credentials (development server)
- Returns:
- datastore credentials.
-
googledatastore.helper.
add_key_path
(key_proto, *path_elements)[source]¶ Add path elements to the given datastore.Key proto message.
- Args:
- key_proto: datastore.Key proto message. path_elements: list of ancestors to add to the key. (kind1, id1/name1, ..., kindN, idN/nameN), the last 2 elements represent the entity key, if no terminating id/name: they key will be an incomplete key.
- Raises:
- TypeError: the given id or name has the wrong type.
- Returns:
- the same datastore.Key.
- Usage:
>>> add_key_path(key_proto, 'Kind', 'name') # no parent, with name datastore.Key(...) >>> add_key_path(key_proto, 'Kind2', 1) # no parent, with id datastore.Key(...) >>> add_key_path(key_proto, 'Kind', 'name', 'Kind2', 1) # parent, complete datastore.Key(...) >>> add_key_path(key_proto, 'Kind', 'name', 'Kind2') # parent, incomplete datastore.Key(...)
-
googledatastore.helper.
add_properties
(entity_proto, property_dict, indexed=None)[source]¶ Add values to the given datastore.Entity proto message.
- Args:
entity_proto: datastore.Entity proto message. property_dict: a dictionary from property name to either a python object or
datastore.Value.- indexed: if the property values should be indexed. None leaves indexing as
- is (defaults to True if value is a python object).
- Usage:
>>> add_properties(proto, {'foo': u'a', 'bar': [1, 2]})
- Raises:
- TypeError: if a given property value type is not supported.
-
googledatastore.helper.
set_property
(property_proto, name, value, indexed=None)[source]¶ Set property value in the given datastore.Property proto message.
- Args:
property_proto: datastore.Property proto message. name: name of the property. value: python object or datastore.Value. indexed: if the value should be indexed. None leaves indexing as is
(defaults to True if value is a python object).- Usage:
>>> set_property(property_proto, 'foo', u'a')
- Raises:
- TypeError: if the given value type is not supported.
-
googledatastore.helper.
set_value
(value_proto, value, indexed=None)[source]¶ Set the corresponding datastore.Value _value field for the given arg.
- Args:
value_proto: datastore.Value proto message. value: python object or datastore.Value. (unicode value will set a
datastore string value, str value will set a blob string value). Undefined behavior if value is/contains value_proto.- indexed: if the value should be indexed. None leaves indexing as is
- (defaults to True if value is not a Value message).
- Raises:
- TypeError: if the given value type is not supported.
-
googledatastore.helper.
get_value
(value_proto)[source]¶ Gets the python object equivalent for the given value proto.
- Args:
- value_proto: datastore.Value proto message.
- Returns:
- the corresponding python object value. timestamps are converted to datetime, and datastore.Value is returned for blob_key_value.
-
googledatastore.helper.
get_property_dict
(entity_proto)[source]¶ Convert datastore.Entity to a dict of property name -> datastore.Value.
- Args:
- entity_proto: datastore.Entity proto message.
- Usage:
>>> get_property_dict(entity_proto) {'foo': {string_value='a'}, 'bar': {integer_value=2}}
- Returns:
- dict of entity properties.
-
googledatastore.helper.
set_kind
(query_proto, kind)[source]¶ Set the kind constraint for the given datastore.Query proto message.
-
googledatastore.helper.
add_property_orders
(query_proto, *orders)[source]¶ Add ordering constraint for the given datastore.Query proto message.
- Args:
- query_proto: datastore.Query proto message. orders: list of propertype name string, default to ascending order and set descending if prefixed by ‘-‘.
- Usage:
>>> add_property_orders(query_proto, 'foo') # sort by foo asc >>> add_property_orders(query_proto, '-bar') # sort by bar desc
-
googledatastore.helper.
add_projection
(query_proto, *projection)[source]¶ Add projection properties to the given datatstore.Query proto message.
-
googledatastore.helper.
set_property_filter
(filter_proto, name, op, value)[source]¶ Set property filter contraint in the given datastore.Filter proto message.
- Args:
- filter_proto: datastore.Filter proto message name: property name op: datastore.PropertyFilter.Operation value: property value
- Returns:
- the same datastore.Filter.
- Usage:
>>> set_property_filter(filter_proto, 'foo', ... datastore.PropertyFilter.EQUAL, 'a') # WHERE 'foo' = 'a'
-
googledatastore.helper.
set_composite_filter
(filter_proto, op, *filters)[source]¶ Set composite filter contraint in the given datastore.Filter proto message.
- Args:
- filter_proto: datastore.Filter proto message op: datastore.CompositeFilter.Operation filters: vararg list of datastore.Filter
- Returns:
- the same datastore.Filter.
- Usage:
>>> set_composite_filter(filter_proto, datastore.CompositeFilter.AND, ... set_property_filter(datastore.Filter(), ...), ... set_property_filter(datastore.Filter(), ...)) # WHERE ... AND ...