Skip to main content

An offline-available ORM-like wrapper for Google Firestore Database

Project description

Firestore

Details:

Firestore is an offline available ORM/ODM atop Google Firestore.

Repository:

https://github.com/workenvoy/firestore

Author:

Workenvoy Inc (http://github.com/workenvoy)

Maintainer:

Raymond Ortserga (http://github.com/rayattack)

https://travis-ci.org/workenvoy/firestore.svg?branch=master https://coveralls.io/repos/github/workenvoy/firestore/badge.svg?branch=master

Details

Firestore is a Python Object-Document/Object-Collections Mapper for working with Google Firestore. The Flexible, Extremely Scalable, realtime database by Google. You can find some documentation at https://firestore.readthedocs.io - and there is also a quickstart tutorial.

Offline Support

Firestore currently uses an in-memory data store to simulate access to Google Firestore when working offline. There is an optimistic persistence to disk and the contents can be seen in the /projectdir/localfire directory. Deleting this directly means you lose all the data you might have saved prior to removing the directory from disk. Make sure to make a copy of this directory if you want to keep a copy of your data and you are encouraged to contribute i.e. open an issue, submit a pull request if you want to offer a helping hand.

Installation

We recommend the use of virtual environments e.g. virtualenv to control your package management. Installation of Firestore is easily done pip install -U firestore and requires pip. to be installed. Otherwise, you can download the source code from GitHub and run python setup.py install.

Dependencies

We tried to keep the dependencies to a minimum, and all dependencies are available using pip. The only dependencies you require to use Firestore are highlighted below:

  • google-cloud-firestore

If you are working with dates extensive we suggest you use a date parser:

  • dateutil>=2.1.0

Examples

Sample Firestore Code Snippet:

from firestore import Collection, Document, Reference as Ref
from firestore import Array
from firestore import Integer
from firestore import String
from firestore.lazy import Datatype

class SomeRootCollection(Collection):
    """
    Root collections inherit directly from collection, whilst
    sub collections will inherit from a document.

    To understand this always remember in Firestore a collection can never be
    a child of another collection, and a sub-collection will always live
    under a document.
    To have mongo style sub-collections use the Map datatype
    """
    pass


class User(SomeRootCollection):
    """
    This is the User document and will be saved under the
    collection `SomeRootCollection`.
    Documents live under collections or sub-collections directly
    """
    __private__ = ["password"]

    first_name = String(required=True)
    middle_name = Datatype(datatype="String")  # You can use Datatype in place of more specific types
    last_name = Datatype("StrInG")  # Case insensitive
    age = Integer(minimum=0)
    photos = Reference('Photo')
    password = String(minimum=6)  # private fields can not be viewed with get_XXX methods


class Photo(User):
    """
    This creates a photos subcollection under the User document for documents
    under the root collection
    """
    id = String(required=True, id=True)  # omit to have id auto-generated by cloud firestore
    photo_urls = Array()


# Create a text-based post
>>> user = User()
>>> user.first_name = "Alan"
>>> user.last_name = "Turing"
>>> user.photos.append("https://cloudinary.com/img.jpg")
>>>
>>> # this will persist user and photo at
>>> # once unlike user.save that will save only user
>>> user.persist()

# Sometimes you want one thing to succeed before doing another
>>> user.photos.safe_save()  # only saves if parent was prior saved else fails
>>> user.photos.save()  # saves regardless

# You can also save a photo by itself and query easily
>>> photo = Photo()
>>> photo.parent = user
>>> photo.save()  # save only photo
>>> photo.parent.save()

Contributing

We love contributors: Contribution guidelines

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

firestore-0.0.7.tar.gz (22.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

firestore-0.0.7-py3.7.egg (78.1 kB view details)

Uploaded Egg

firestore-0.0.7-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file firestore-0.0.7.tar.gz.

File metadata

  • Download URL: firestore-0.0.7.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for firestore-0.0.7.tar.gz
Algorithm Hash digest
SHA256 ba2da803b708ac4ee6951406431528382f371825deb391995adb7a2670c343a1
MD5 d48aee5cb015770523369d32370715dd
BLAKE2b-256 c39cc6ae77489a3296b035cf9985d9a707867d2a623bfd20f93baa259ab1235f

See more details on using hashes here.

File details

Details for the file firestore-0.0.7-py3.7.egg.

File metadata

  • Download URL: firestore-0.0.7-py3.7.egg
  • Upload date:
  • Size: 78.1 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for firestore-0.0.7-py3.7.egg
Algorithm Hash digest
SHA256 df4bfa1d295fa9e73e4f34226b64f292b2b5b38e9c3c83f3ca1508b523a8e6ef
MD5 ace2317988c9c20f49b90f6bc773724a
BLAKE2b-256 7737b58265167721e1a1c284ede0e45244a90d9961fec6bb927fc9c583056783

See more details on using hashes here.

File details

Details for the file firestore-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: firestore-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for firestore-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5b23a2bbd027940c8e4e7f953541cb3bc5b2f082113742ff8c8ffa5c9de3e226
MD5 fb6d268cc7d862a12906f57e6550b034
BLAKE2b-256 6d8f191cd68455c3fe1813b9ee782bf8beb91b23ec08d28f54baa0beb0be8082

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page