Skip to main content

sj-firebase-python

Implement Firebase Java SDK in Python

GitAds Sponsored

Sponsored by GitAds

Firebase

Make your app the best it can be

Firebase is an app development platform that helps you build and grow apps and games users love. Backed by Google and trusted by millions of businesses around the world.

Usage

Buildozer Android project

android.gradle_dependencies = io.github.simplejnius:sjfirebase:1.3.2
requirements = sjfirebase

The current version of python-for-android lacks support for incorporating bom dependencies, modifying the classpath, and copying the google-service.json. To address this limitation, a fork of python-for-android has been developed to include these functionalities. To implement these changes in your buildozer.spec file, make adjustments to the specified section using the provided values below:

android.api = 34
android.enable_androidx = True
android.gradle_dependencies = io.github.simplejnius:sjfirebase:1.3.2,
    com.google.firebase:firebase-auth,com.google.firebase:firebase-database,
    com.google.firebase:firebase-firestore,com.google.firebase:firebase-storage,
    com.google.firebase:firebase-analytics
p4a.fork = SimpleJnius
p4a.branch = firebase

Important Note: Upon creating an Android project within your Firebase Console, ensure to transfer the google-service.json file to the same location as your main.py file.

Python(Buildozer) installation

# pip
pip install sjfirebase

# buildozer.spec
requirements = sjfirebase

Sample Code Documentation

To add, set, update, and delete a document in a collection

from kivy.uix.screenmanager import Screen  # noqa
from sjfirebase.tools.mixin import FirestoreMixin


class MyScreen(Screen, FirestoreMixin):
    
    def on_event1(self):
        data = dict(name=self.ids.name.text, email=self.ids.email.text)
        
        # creates a new document in "individual" collection and
        # passes a success(True/False) and error(None or FirebaseException)
        # parameters to your callback
        self.add_document("individuals", data, lambda success, error: print(success, error))
    
    def on_event2(self):
        data = dict(name=self.ids.name.text, email=self.ids.email.text)
        
        # creates a new or overwrite document "custom_document_id" in collection
        # and passes a success(True/False) and error(None or FirebaseException)
        # parameters to your callback
        self.set_document("individual/custom_document_id", data, lambda success, error: print(success, error))
    
    def on_event3(self):
        data = dict(name=self.ids.name.text, email=self.ids.email.text)
        
        # creates a new or update document "custom_document_id" in collection
        # and passes a success(True/False) and error(None or FirebaseException)
        # parameters to your callback
        self.set_document("individual/custom_document_id", data, lambda success, error: print(success, error), merge=True)
    
    def on_event4(self):
        data = ["name", self.ids.name.text, "email", self.ids.email.text]
        
        # creates a new or overwrite document "custom_document_id" in collection
        # and passes a success(True/False) and error(None or FirebaseException)
        # parameters to your callback.
        # Notice the data is a list, and this list must be an even length and not odd length.
        # Every odd values are the key while the even values are the value.
        # E.g in the above `data` `name` is the key while `self.ids.name.text` is the value
        # same goes with the email. It's this way due to the varargs nature of the Firestore `update` method
        # signature
        self.update_document("individual/custom_document_id", data, lambda success, error: print(success, error))
        
    def on_event5(self):
        # deletes document "custom_document_id"
        self.delete_document("individual/custom_document_id", lambda success, error: print(success, error))

# NB: You can instantiate the FirestoreMixing directly
# E.g
f = FirestoreMixin()
f.add_document(...)
f.set_document(...)
# etc..

To get-data, paginate-data, and get-realtime-updates

from kivy.uix.screenmanager import Screen  # noqa
from sjfirebase.tools.mixin import FirestoreMixin


class MyScreen(Screen, FirestoreMixin):
    def on_event1(self):
        # gets a dictionary of data from "document_id" if any data and passes
        # `success` (True/False) and `data` (dict/errorMessage).
        # always check if success is True before accessing items from data,
        # or check if data is an instance of dict. Else log the data to see the error message
        self.get_document("individual/document_id", lambda success, data: print(success, data))
    
    def on_event2(self):
        # everything @on_event1 plus `source` that states where the data should be fetched.
        # either cache, server or default. cache gets from firebase data stored locally
        # on the device for offline purposes while server gets from firebase cloud directly.
        # default can be either cache or cloud depending on your configuration.
        self.get_document("individual/document_id", lambda success, data: print(success, data), source="cache")
    
    def on_event3(self):
        # gets all document at "individual" collection and passes success and data argument.
        # here, data is a list of dict. before accessing, refer to @on_event1
        self.get_collection_of_documents("individual", lambda success, data: print(success, data))
    
    def on_event4(self):
        # refer to @on_event2 for "source" and @on_event3 for functionality description
        self.get_collection_of_documents("individual", lambda success, data: print(success, data), source="cache")

    def on_event5(self):
        # refer to @on_event3 for functionality description. The new thing here is `limit`.
        # limit is used to limit the amount of data you fetch from firebase and paginate as you go.
        self.get_pagination_of_documents("individual", 10, lambda success, data: print(success, data))

    def on_event6(self):
        # listens for document changes and returns a dict of data and location
        # where the data is coming from. `data`(dict/errorMessage), where("Local"/"Server")
        self.add_document_snapshot_listener("individual/document_id", lambda data, where: print(data, where))
    
    def on_event7(self):
        # same as @on_event6 but gets a list of document with information on whether they were
        # added, removed or modified
        self.add_collection_snapshot_listener("individual", lambda data, where: print(data, where))

Python API

ActionCodeSettings

class sjfirebase.jclass.action.ActionCodeSettings

Structure that contains the required continue/state URL with optional Android and iOS bundle identifiers. The stateUrl used to initialize this class is the link/deep link/fallback url used while constructing the Firebase dynamic link.

methods

  • newBuilder
Visit ActionCodeSettings Documentation for more API

SJFirebaseAuthEmai

class sjfirebase.jclass.emailauth.SJFirebaseAuthEmail

The entry point of the Firebase Authentication SDK. First, obtain an instance of this class by calling get_instance

methods

  • check_user_signed_in
  • get_instance
Visit FirebaseAuth Documentation for more API

SJFirebaseDatabase

class sjfirebase.jclass.database.SJFirebaseDatabase

The entry point for accessing a Firebase Database. You can get an instance by calling getInstance. To access a location in the database and read or write data, use get_ref

methods

  • get_db
  • get_ref
Visit FirebaseDatabase Documentation for more API

SJFirebaseFirestore

class sjfirebase.jclass.firestore.SJFirebaseFirestore

methods

  • get_db
Visit FirebaseFirestore Documentation for more API

SJFirebaseUser

class sjfirebase.jclass.user.SJFirebaseUser

Represents a user's profile information in your Firebase project's user database. It also contains helper methods to change or retrieve profile information, as well as to manage that user's authentication state.

methods

  • get_current_user
  • profile_change_request_builder
Visit FirebaseUser Documentation for more API

SJFirebaseStorage

class sjfirebase.jclass.user.SJFirebaseStorage

FirebaseStorage is a service that supports uploading and downloading large objects to Google Cloud Storage. Pass a custom instance of FirebaseApp to get_instance which will initialize it with a storage location (bucket) specified via setStorageBucket.

Otherwise, if you call getReference without a FirebaseApp, the FirebaseStorage instance will initialize with the default FirebaseApp obtainable from get_instance. The storage location in this case will come the JSON configuration file downloaded from the web

methods

  • get_instance
Visit FirebaseStorage Documentation for more API

OnCompleteListener

class sjfirebase.jinterface.google

OnCompleteListener

Listener called when a Task completes.

methods

  • onComplete
Visit OnCompleteListener Documentation for more API

ValueEventListener

class sjfirebase.jinterface.firebase.ValueEventListener

methods

  • onDataChange
  • onCancelled
Visit ValueEventListener Documentation for more API

Metadata

Release files for sjfirebase 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sjfirebase 1.7.0
File Size Uploaded Provenance Actions
sjfirebase-1.7.0.tar.gz 21.8 kB Without provenance Details for sjfirebase-1.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sjfirebase 1.7.0
File Interpreter ABI Platform Actions
sjfirebase-1.7.0-py3-none-any.whl Python 3 none any Details for sjfirebase-1.7.0-py3-none-any.whl

Total release size: 51.0 kB

Release files / sjfirebase-1.7.0.tar.gz

Download URL sjfirebase-1.7.0.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8d1bafbab060500cdfe12dab28b7e5c37ee716b6c4f7fa7554823dd47f0e62d9
BLAKE2b-256 checksum
How to use checksums
f2a52a03dcff41e7394d7bbfe349382909393cc9a8134cc8f914f194f0de9639
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.13.8 Linux/6.14.0-36-generic

Release files / sjfirebase-1.7.0-py3-none-any.whl

Download URL sjfirebase-1.7.0-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ad4b9b6c9522dd0ec47b675e67da7247e81740326b0d7c02307223f0077e0b3
BLAKE2b-256 checksum
How to use checksums
ef379ae8651b6fedc870f88ea7e1d374fd5c5fa411e2543f1355d7a41bbdbb2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.13.8 Linux/6.14.0-36-generic

Security for sjfirebase 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page