Metadata-Version: 2.1
Name: firedantic
Version: 0.1.1
Summary: Pydantic base model for Firestore
Home-page: https://github.com/digitalliving/firedantic
License: BSD-3-Clause
Author: Digital Living International Ltd
Requires-Python: >=3.6,<4.0
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Requires-Dist: google-cloud-firestore (>=1.9.0,<2.0.0)
Requires-Dist: grpcio (>=1.32.0,<2.0.0)
Requires-Dist: pydantic (>=1.6.1,<2.0.0)
Project-URL: Repository, https://github.com/digitalliving/firedantic
Description-Content-Type: text/markdown

# Firedantic

[![Build Status](https://travis-ci.org/digitalliving/firedantic.svg?branch=master)](https://travis-ci.org/digitalliving/firedantic)

Database models for Firestore using Pydantic base models.

## Installation

The package is available on PyPi:

```bash
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.

```python
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:

```python
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](./LICENSE) file.

