Skip to main content

Pydantic base model for Firestore

Project description

Firedantic

Build Status

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 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 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()

# Prints out the firestore ID of the Company model
print(company.id)

License

This code is released under the BSD 3-Clause license. Details in the LICENSE file.

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

firedantic-0.1.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

firedantic-0.1.3-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file firedantic-0.1.3.tar.gz.

File metadata

  • Download URL: firedantic-0.1.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.7 Linux/4.15.0-1077-gcp

File hashes

Hashes for firedantic-0.1.3.tar.gz
Algorithm Hash digest
SHA256 757ac155401b05d174d6754c45dc4afe7052dd5ef6d508f24a8b2cadf7b0fd17
MD5 ae8de11c2eb6908fcafc3a6fc193661f
BLAKE2b-256 19a2fda4d78f682e6faa85dd87a93a2b024aa140de5f58be8c4615c2eea2ca26

See more details on using hashes here.

File details

Details for the file firedantic-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: firedantic-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.7 Linux/4.15.0-1077-gcp

File hashes

Hashes for firedantic-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 daa06a3ffd5a3cfc3f635d85930dfa83abe694f6be51b8fb16c4a441e79bc48c
MD5 5e71fc3db2d12286f9be9093938b8bf1
BLAKE2b-256 e367c4cc46f561bf30461108ed11d4f085d7a0bae369388a38e521edae506cd4

See more details on using hashes here.

Supported by

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