Simple Firestore ORM
Project description
Firedom
Simple Firestore ORM for Python.
Installation
pip install firedom
Usage
Create an instance of the library's main class:
firedom = Firedom(service_account_json_path='your-credentials.json')
Define the model of your collection by inheriting from the Model
property of the instance you created:
@dataclass # <- Required
class User(firedom.Model):
username: str
email: int
country: str
city: str
is_active: bool = True
number_of_pets: int = 0
class Config:
# Required: Field to be used as document ID
document_id_field = 'username'
# Optional: Collection ID
collection_id = 'users'
Manipulate the documents in your collection:
# Get a document from the collection
user = User.collection.get('afuenzalida')
# Delete a document from the collection
user = User.collection.get('usuario_malvado')
user.delete()
# Get all documents in the collection
users = User.collection.all()
# Filter documents in the collection
users = User.collection.where(
User.country == 'Chile',
User.is_active == True,
User.city.is_in(['Santiago', 'Valparaíso']),
User.number_of_pets > 1,
)
Chain queries:
# Sort the documents obtained in a query:
users = User.collection.where(
User.country == 'Chile',
).order_by(
'email',
desc=True,
)
# Delete documents obtained in a query:
users = User.collection.all().delete()
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
firedom-1.0.0.tar.gz
(6.9 kB
view hashes)