Skip to main content

A modern async Firebase library

Project description

firebasil

CI codecov PyPI Documentation Status

A modern async Firebase client.

Features

Auth

Auth Baseline Auth High level

The AuthClient async context manager provides access to auth routines. Every method returns a typed object with the information provided by the Firebase auth REST API.

from firebasil.auth import AuthClient


async with AuthClient(api_key=...) as auth_client:
    # Sign up a new user
    signed_up = await auth_client.sign_up("kevin@k2bd.dev", "password1")

    # Sign in as a user
    signed_in = await auth_client.sign_in_with_password(
        email="kevin@k2bd.dev",
        password="password1",
    )

    updated = await auth_client.update_profile(
        signed_in.id_token,
        display_name="Kevin Duff",
    )

The AuthClient class will use production GCP endpoints and routes for auth by default, unless the FIREBASE_AUTH_EMULATOR_HOST environment variable is set, in which case the defaults change to the emulator. This can be overridden in both cases by passing in identity_toolkit_url, secure_token_url, and use_emulator_routes explicitly.

Common error codes are promoted to exception classes, so these can be directly handled in code without having to parse the error response body.

Realtime Database (RTDB)

RTDB Baseline RTDB High level

The Rtdb async context manager yields the root node of the database.

from firebasil.rtdb import Rtdb


async with Rtdb(database_url=...) as root_node:

    # Set the database state from the root node
    await rtdb_root.set({"scores": {"a": 5, "b": 4, "c": 3, "d": 2, "e": 1}})

    # Build a child node that references the 'scores' path
    child_node: RtdbNode = rtdb_root / "scores"

    # Get the value of the further 'c' child
    c_value = await (child_node / "c").get()
    assert c_value == 3

    # Query for the last two entries at that location, ordered by key
    query_value = await child_node.order_by_key().limit_to_last(2).get()
    assert query_value == {"d": 2, "e": 1}

    # Watch a node for live changes
    async with child_node.events() as event_queue:
        event: RtdbEvent = await event_queue.get()
        ...
        # Somewhere, 'b' gets set to 7
        # RtdbEvent(event=EventType.put, path='/b', data=7)

Either a user ID token, or a machine credential access token, can be provided Rtdb through the id_token or access_token arguments, which will be used to pass the database's auth.

A local emulator URL may be passed to Rtdb to test against the Firebase Emulator Suite.

Firestore Database

Firestore Baseline

Still in planning!

Storage

Storage Baseline

Still in planning!

Developing on this Project

Installation

Install Poetry and poetry install the project

Install the Firebase CLI. Make sure the emulators are installed and configured with firebase init emulators.

Useful Commands

Note: if Poetry is managing a virtual environment for you, you may need to use poetry run poe instead of poe

  • poe autoformat - Autoformat code
  • poe lint - Linting
  • poe test - Run tests
  • poe docs - Build docs

Release

Release a new version by manually running the release action on GitHub with a 'major', 'minor', or 'patch' version bump selected. This will create an push a new semver tag of the format v1.2.3.

Pushing this tag will trigger an action to release a new version of your library to PyPI.

Optionally create a release from this new tag to let users know what changed.

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

firebasil-0.3.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

firebasil-0.3.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file firebasil-0.3.0.tar.gz.

File metadata

  • Download URL: firebasil-0.3.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.15.0-1022-azure

File hashes

Hashes for firebasil-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2041d6b1003f48dad325380fb4742ce436844424dd46b9f57bc6ab2f3d5c49fa
MD5 059922d6d95e1b1d1ecdbe7262db3592
BLAKE2b-256 b387fb5110de5d70119f94868b32f26f3d84dade99ce263bc64f862e0eb8a237

See more details on using hashes here.

File details

Details for the file firebasil-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: firebasil-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.15.0-1022-azure

File hashes

Hashes for firebasil-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38f32991e6258f3a91cb852df8859bdb51cbc8d414f7e95fbbe66655ee192e04
MD5 c4bc400cfe383bf7c57a90ffa3b4d322
BLAKE2b-256 1e4d8b153bdb0d9b10361bc9e23c805015779ef3c77ee5e43ee5876589bfeb71

See more details on using hashes here.

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