Firestore Collections
Simple Firestore collection definitions and queries using pydantic schemas and Firestore query API.
A quick and easy way to make use of the NoSQL document database solution Firestore available in Google Cloud Platform (GCP).
Requirements
- Python 3.6+
- GCP project with Firestore enabled
Features
- Schema definition and validation: Define collection schemas using
pydanticand built-in type hinting (typing). - Automatic IDs: Automatic ID generation using 12-byte hexadecimal (
bson.ObjectId). - Simple queries: Query collections using a simple interface.
- Auxiliary timestamps: Automatically added timestamps to objects like
created_atandupdated_at.
Example
Define users collection and perform different queries:
from typing import Optional
from pydantic import EmailStr, SecretStr
from firestore_collections import Collection, Schema
class User(Schema):
__collection_name__ = 'users'
__unique_keys__ = ['email']
email: EmailStr
full_name: str = None
password: Optional[SecretStr]
# Initialize firestore collection
collection = Collection(schema=User)
# Initialize user object
user = User(
email='john@doe.com',
full_name='John')
# Insert
user = collection.insert(user)
# Get object from db
user = collection.get(user.id)
# Update
user.full_name = 'John Doe'
collection.update(user)
# Get by attribute
user = collection.get_by_attribute('email', 'john@doe.com')
# Get all objects
users = collection.get_all()
# Delete object
collection.delete(id=user.id)
GCP credentials
NOTE: The package assumes a valid GCP credentials file is available and its path defined in the environment variable GOOGLE_APPLICATION_CREDENTIALS.
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for firestore-collections 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| firestore-collections-0.5.2.tar.gz | 9.4 kB | Details |
Release files / firestore-collections-0.5.2.tar.gz
| Download URL | firestore-collections-0.5.2.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bd62528324d72ec21b3b1c52fa89f4a6ca9f6a66be64b5e3f6a77d99828ded6
|
|
BLAKE2b-256 checksum How to use checksums |
85f817421287902f20112fc17d3ba7d8c0bea984f9d70f2ff0493ce8abe7a4b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.2
|