Skip to main content

μDatastore: ODM for Google Cloud Datastore

Implemented as framework in the μMongo library (a python ODM for MongoDB)

While working Google Cloud Datastore, most of our code uses the google-cloud-datastore package, for creating, updating and querying entities. We often find ourselves writing code to export objects to datastore.Entity, and import from entities to objects. On AppEngine, there is ndb which avoids this, so the idea emerged to create an ODM for datastore ourselves.

Having worked with μMongo before, a prototype was created which implements an additional framework based on following conventions:

  • A datastore partition (project/namespace) corresponds to a mongo database
  • A datastore entity kind corresponds to a mongo collection
  • The datastore __key__ field corresponds to the mongo _id field

Install

pip install udatastore

Example

from datetime import datetime
from google.cloud import datastore
from udatastore import DataStoreInstance
from umongo import Document, fields, validate


db = datastore.Client(project="dummy", namespace='abcd')
instance = DataStoreInstance()
instance.init(db)


@instance.register
class User(Document):
    email = fields.EmailField(required=True, unique=True)
    birthday = fields.DateTimeField(validate=validate.Range(min=datetime(1900, 1, 1)))
    friends = fields.ListField(fields.ReferenceField("User"))

goku = User(email='goku@sayen.com', birthday=datetime(1984, 11, 20))
goku.commit()
vegeta = User(email='vegeta@over9000.com', friends=[goku])
vegeta.commit()

vegeta.friends
# <object umongo.data_objects.List([<object udatastore.reference.DataStoreReference(document=User, pk=<Key('User', 4476), project=dummy>)>])>
vegeta.dump()
# {'email': 'vegeta@over9000.com', 'id': '4477', 'friends': [<Key('User', 4476), project=dummy>]}
User.find_one({"email": 'goku@sayen.com'})
# <object Document __main__.User({'email': 'goku@sayen.com', 'id': 4474,
#                                 'friends': <object umongo.data_objects.List([])>,
#                                 'birthday': datetime.datetime(1984, 11, 20, 0, 0)})>

Limitations:

Not all features of μMongo are available or work exactly the same in μDatastore:

  • No indexes
  • We do not currently support all field types
  • Datastore converts any datetime to UTC timezone. For now, μDatastore overrides this behaviour and always works with unaware datetimes.
  • We bring our own ReferenceField implementation. You are free to use umongo.fields.ReferenceField, as the DataStoreBuilder will automatically replace these fields with our implementation. We also disable the io_validation on reference fields. Because datastore is eventually consistent this may report errors when creating references to previously created entities.

Metadata

Release files for udatastore 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for udatastore 0.1.7
File Size Uploaded Provenance Actions
udatastore-0.1.7.tar.gz 10.0 kB Without provenance Details for udatastore-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for udatastore 0.1.7
File Interpreter ABI Platform Actions
udatastore-0.1.7-py2.py3-none-any.whl Python 3, Python 2 none any Details for udatastore-0.1.7-py2.py3-none-any.whl

Total release size: 27.7 kB

Release files / udatastore-0.1.7.tar.gz

Download URL udatastore-0.1.7.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
608eb2d49f504f309c0f3c07dd4a182c720c0526348d252fb35d374f6f130ddd
BLAKE2b-256 checksum
How to use checksums
328872fa762661e10fab4fab607bae13d567ec8c1cb65d1c921c37412465efa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

Release files / udatastore-0.1.7-py2.py3-none-any.whl

Download URL udatastore-0.1.7-py2.py3-none-any.whl
Size 17.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b409cbbf1c6ae793e2af5822b9a1a3c01b71f3a2ba6b34182c2e956e0527f7dd
BLAKE2b-256 checksum
How to use checksums
a9a5c38414af6fe1b48025e916c2be278a35fe1e2f408a07e71829cf43829805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

Security for udatastore 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page