Simple Firestore collection definitions and queries using pydantic schemas and Firestore query API.
Project description
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.
Requirements
- Python 3.6+
Features
- Schema definition and validation: Define collection schemas using
pydantic
and 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_at
andupdated_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'
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)
License
This project is licensed under the terms of the MIT license.
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
Close
Hashes for firestore-collections-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e2f44639f2885b670a8753c144d45a7911b0bf060baa886ebd27dd1ea644db1 |
|
MD5 | 33f1b126b9f20b8daa4863c248c07adc |
|
BLAKE2b-256 | 95438b9426f7aa6863ca855d71929a6918b8b0c3123a2d125ac2a762ac94d7c2 |