Skip to main content

Simple Firebase RTDB wrapper

Project description

Firebase Service

Simple Python wrapper for Firebase Realtime Database using firebase-admin.

Install

pip install firebase-service

Setup

  1. Create a Firebase project
  2. Generate a service account JSON
  3. Place it in your project root as:
firebase.json

The package loads firebase.json from the current working directory (CWD).


Usage

from firebase_service import FirebaseService

db = FirebaseService("test_node")

db.set("counter", 0)
print(db.get("counter"))

db.increment("counter", 5)
print(db.get("counter"))

Root Values

You can use None to access the root of your node:

db.set(None, "hello")
print(db.get(None))

Methods

get(directory=None)

Get data from a path.

set(directory, value)

Set a value at a path.

delete(directory)

Delete a value.

increment(directory, delta=1)

Atomically increment a number.

update(directory, callback)

Update a value using a function.

db.update("counter", lambda x: x * 2)

Example

from firebase_service import FirebaseService

emotion = FirebaseService("emotion_node")

emotion.set(None, "neutral")

def next_state(state):
    order = ["neutral", "happy", "sad", "angry"]
    return order[(order.index(state) + 1) % len(order)] if state in order else "neutral"

emotion.update(None, next_state)
print(emotion.get(None))

Notes

  • Requires firebase.json in the working directory
  • Uses Firebase Admin SDK
  • Designed for simple scripts and small backends

License

MIT

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

firebase_service-0.1.0.tar.gz (40.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

firebase_service-0.1.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file firebase_service-0.1.0.tar.gz.

File metadata

  • Download URL: firebase_service-0.1.0.tar.gz
  • Upload date:
  • Size: 40.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for firebase_service-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7da5ba7e40e66c1a7ee056dec30db4964e62c2da218476edb1dc67c6a4d7e97b
MD5 35ada183df01cce3a6555cce2c49eaeb
BLAKE2b-256 a098dcbb14fe40c2ca6c487d74c06710b021b08229c4ee737feefefb4bf413ff

See more details on using hashes here.

File details

Details for the file firebase_service-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for firebase_service-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ae66281b21ec5d2655a6c40f6ab0ff9f083f2dc4318dec4d66204f92d84351b
MD5 dc37d65c79f0265f8cc2e579cf5fd2a3
BLAKE2b-256 6c1292becab5fb52b75846077b16b374211e9c8bb2155870252835ea86a73ba2

See more details on using hashes here.

Supported by

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