Skip to main content

Firestore + Dataclass: declare and interact with your Firestore models using dataclasses.

Project description

Build Status

Fireclass

Firestore + Dataclass: declare and interact with your Firestore models using dataclasses.

Installation

pip install fireclass

Sample usage

from dataclasses import dataclass
from google.cloud import firestore
from fireclass.document import Document, initialize_with_firestore_client


# Define a new type of document as a dataclass
@dataclass
class Person(Document):
    email_address: str
    age: int


# Initialize access to the Firestore DB
client = firestore.Client.from_service_account_json("service-account.json")
initialize_with_firestore_client(client)

# Create a new person
person = Person(email_address='test@test.com', age=30)

# Save the person to the DB
person.create()

# Update a field
person.age = 31
person.update()

# Fetch this specific person
fetched_person = Person.get_document(person.id)

# Query for persons
for found_person in Person.where("age", "==", 31).stream():
    print(found_person)

# Delete the person from the DB
person.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

fireclass-1.0.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Supported by

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