Asyncio Python Client for Google Cloud Datastore
Project description
Installation
$ pip install --upgrade gcloud-aio-datastore
Usage
We’re still working on documentation; for now, this should help get you started:
from gcloud.aio.datastore import Datastore
from gcloud.aio.datastore import Key
from gcloud.aio.datastore import PathElement
from gcloud.aio.datastore import GQLQuery
ds = Datastore('my-gcloud-project', '/path/to/creds.json')
key1 = Key('my-gcloud-project', [PathElement('Kind', 'entityname')])
key2 = Key('my-gcloud-project', [PathElement('Kind', 'entityname2')])
# batched lookups
entities = await ds.lookup([key1, key2])
# convenience functions for any datastore mutations
await ds.insert(key1, {'a_boolean': True, 'meaning_of_life': 41})
await ds.update(key1, {'a_boolean': True, 'meaning_of_life': 42})
await ds.upsert(key1, {'animal': 'aardvark'})
await ds.delete(key1)
# or build your own mutation sequences with full transaction support
transaction = await ds.beginTransaction()
try:
mutations = [
ds.make_mutation(Operation.INSERT, key1, properties={'animal': 'sloth'}),
ds.make_mutation(Operation.UPSERT, key1, properties={'animal': 'aardvark'}),
ds.make_mutation(Operation.INSERT, key2, properties={'animal': 'aardvark'}),
]
await ds.commit(transaction, mutations=[mutation])
except Exception:
await ds.rollback(transaction)
# support for partial keys
partial_key = Key('my-gcloud-project', [PathElement('Kind')])
# and ID allocation or reservation
allocated_keys = await ds.allocateIds([partial_key])
await ds.reserveIds(allocated_keys)
# query support
query = GQLQuery('SELECT * FROM the_meaning_of_life WHERE answer = @answer',
named_bindings={'answer': 42})
results = await ds.runQuery(query, session=s)
Contributing
Please see our contributing guide.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for gcloud-aio-datastore-2.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14d297fa01f3227a49925204d46866f3e8878a7081b191d7384ce42f803b1423 |
|
MD5 | b60dc7785e247dc145526a695adb5565 |
|
BLAKE2b-256 | 7d672e6be7d15d41261f37ded04e845c7ed4de4d5540b87784282658e1cc73a0 |
Close
Hashes for gcloud_aio_datastore-2.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b1a2dbc3507098d754db39fc65dc90a3103b9586bfe30a12f682db612b3c614 |
|
MD5 | 2c0c97f4aca2037044d2e6bfc45964d5 |
|
BLAKE2b-256 | 5b24ff5b0a38d69acea72cadb75a96532ee20f7e9bda8245ab47e2d876278afc |