Giter Site home page Giter Site logo

nabla-c0d3 / fireclass Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 4.0 172 KB

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

License: MIT License

Python 100.00%
python dataclasses firestore google-cloud google-cloud-platform python37 orm

fireclass's Introduction

Fireclass

Build Status Downloads PyPI version Python version

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

Installation

pip install fireclass

Sample usage

from dataclasses import dataclass
from enum import Enum

from google.cloud import firestore
from fireclass import Document, initialize_with_firestore_client


class MembershipLevelEnum(Enum):
    NONE = 1
    INTERMEDIATE = 2
    FULL = 3


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

    # Enum fields are supported
    membership: MembershipLevelEnum


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

# Create a new person
person = Person(email_address="[email protected]", age=30, membership=MembershipLevelEnum.INTERMEDIATE)

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

# Update some fields
person.age = 31
person.membership = MembershipLevelEnum.NONE
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 document from the DB
person.delete()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.