Pydantic base model for Firestore
Project description
Firedantic
Database models for Firestore using Pydantic base models.
Installation
The package is available on PyPi:
pip install firedantic
Usage
In your application you will need to configure the firestore db client and optionally the collection prefix, which by default is empty.
from mock import Mock
from os import environ
import google.auth.credentials
from firedantic.configurations import configure
from google.cloud import firestore
# Firestore emulator must be running if using locally.
if environ.get("FIRESTORE_EMULATOR_HOST"):
client = firestore.Client(
project="firedantic-test",
credentials=Mock(spec=google.auth.credentials.Credentials)
)
else:
client = firestore.Client()
configure(client, prefix="firedantic-test-")
Once that is done, you can start defining your Pydantic models, e.g:
from pydantic import BaseModel
from firedantic.models import Model
class Owner(BaseModel):
"""Dummy owner Pydantic model."""
first_name: str
last_name: str
class Company(Model):
"""Dummy company Firedantic model."""
__collection__ = "companies"
company_id: str
owner: Owner
# Now you can use the model to save it to Firestore
owner = Owner(first_name="John", last_name="Doe")
company = Company(company_id="1234567-8", owner=owner)
company.save()
print(company.id)
License
This code is released under the BSD 3-Clause license. Details in the LICENSE file.
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
firedantic-0.1.0.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for firedantic-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 203816d654f71de87a552d007b14807975ea07b9c021beb8179bc0bfe41f5e33 |
|
MD5 | d3a99469cb43258054b2ca1b3defae3e |
|
BLAKE2b-256 | 934118ba743f1d85390c2bb0ad356be3078f5e7894c37b836f5112d422a75f21 |