{"id":23055467,"url":"https://github.com/simplejnius/sj-firebase-python","last_synced_at":"2025-08-15T05:32:12.264Z","repository":{"id":211810700,"uuid":"729949138","full_name":"SimpleJnius/sj-firebase-python","owner":"SimpleJnius","description":"Port Firebase to Python","archived":false,"fork":false,"pushed_at":"2024-08-04T15:00:12.000Z","size":38,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-04T16:39:44.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimpleJnius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-10T20:52:08.000Z","updated_at":"2024-08-04T15:00:15.000Z","dependencies_parsed_at":"2023-12-11T02:26:53.524Z","dependency_job_id":"165bc4c7-3f65-483f-8be1-a58f0d4555eb","html_url":"https://github.com/SimpleJnius/sj-firebase-python","commit_stats":null,"previous_names":["simplejnius/sj-firebase-python"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-firebase-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-firebase-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-firebase-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-firebase-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimpleJnius","download_url":"https://codeload.github.com/SimpleJnius/sj-firebase-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229893941,"owners_count":18140620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T01:12:20.395Z","updated_at":"2025-08-15T05:32:12.246Z","avatar_url":"https://github.com/SimpleJnius.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sj-firebase-python\n Implement Firebase Java SDK in Python\n\n \u003c!-- GitAds-Verify: V1Y658YQ4CT1W7YNRP6RCUDTVARQMDOM --\u003e\n ## GitAds Sponsored\n[![Sponsored by GitAds](https://gitads.dev/v1/ad-serve?source=simplejnius/sj-firebase-python@github)](https://gitads.dev/v1/ad-track?source=simplejnius/sj-firebase-python@github)\n\n\n\n*[Firebase](https://firebase.google.com/)*\n\u003e Make your app the\n\u003e best it can be\n\u003e \n\u003e Firebase is an app development platform that helps you build and grow apps and games users love. \n\u003e Backed by Google and trusted by millions of businesses around the world.\n\n## Usage\n### Buildozer Android project\n```properties\nandroid.gradle_dependencies = io.github.simplejnius:sjfirebase:1.3.2\nrequirements = sjfirebase\n```\nThe current version of [python-for-android](https://github.com/kivy/python-for-android) \nlacks support for incorporating bom dependencies, modifying the classpath, and copying the `google-service.json`. \nTo address this limitation, a fork of python-for-android has been developed to include these functionalities. \nTo implement these changes in your `buildozer.spec` file, \nmake adjustments to the specified section using the provided values below:\n```properties\nandroid.api = 34\nandroid.enable_androidx = True\nandroid.gradle_dependencies = io.github.simplejnius:sjfirebase:1.3.2,\n    com.google.firebase:firebase-auth,com.google.firebase:firebase-database,\n    com.google.firebase:firebase-firestore,com.google.firebase:firebase-storage,\n    com.google.firebase:firebase-analytics\np4a.fork = SimpleJnius\np4a.branch = firebase\n```\n**Important Note:** Upon creating an Android project within your [Firebase Console](https://firebase.google.com), \nensure to transfer the `google-service.json` file to the same location as your `main.py` file.\n#### Python(Buildozer) installation\n```shell\n# pip\npip install sjfirebase\n\n# buildozer.spec\nrequirements = sjfirebase\n```\n\n## Sample Code Documentation\n\n**To add, set, update, and delete a document in a collection**\n```python\nfrom kivy.uix.screenmanager import Screen  # noqa\nfrom sjfirebase.tools.mixin import FirestoreMixin\n\n\nclass MyScreen(Screen, FirestoreMixin):\n    \n    def on_event1(self):\n        data = dict(name=self.ids.name.text, email=self.ids.email.text)\n        \n        # creates a new document in \"individual\" collection and\n        # passes a success(True/False) and error(None or FirebaseException)\n        # parameters to your callback\n        self.add_document(\"individuals\", data, lambda success, error: print(success, error))\n    \n    def on_event2(self):\n        data = dict(name=self.ids.name.text, email=self.ids.email.text)\n        \n        # creates a new or overwrite document \"custom_document_id\" in collection\n        # and passes a success(True/False) and error(None or FirebaseException)\n        # parameters to your callback\n        self.set_document(\"individual/custom_document_id\", data, lambda success, error: print(success, error))\n    \n    def on_event3(self):\n        data = dict(name=self.ids.name.text, email=self.ids.email.text)\n        \n        # creates a new or update document \"custom_document_id\" in collection\n        # and passes a success(True/False) and error(None or FirebaseException)\n        # parameters to your callback\n        self.set_document(\"individual/custom_document_id\", data, lambda success, error: print(success, error), merge=True)\n    \n    def on_event4(self):\n        data = [\"name\", self.ids.name.text, \"email\", self.ids.email.text]\n        \n        # creates a new or overwrite document \"custom_document_id\" in collection\n        # and passes a success(True/False) and error(None or FirebaseException)\n        # parameters to your callback.\n        # Notice the data is a list, and this list must be an even length and not odd length.\n        # Every odd values are the key while the even values are the value.\n        # E.g in the above `data` `name` is the key while `self.ids.name.text` is the value\n        # same goes with the email. It's this way due to the varargs nature of the Firestore `update` method\n        # signature\n        self.update_document(\"individual/custom_document_id\", data, lambda success, error: print(success, error))\n        \n    def on_event5(self):\n        # deletes document \"custom_document_id\"\n        self.delete_document(\"individual/custom_document_id\", lambda success, error: print(success, error))\n\n# NB: You can instantiate the FirestoreMixing directly\n# E.g\nf = FirestoreMixin()\nf.add_document(...)\nf.set_document(...)\n# etc..\n```\n\n**To get-data, paginate-data, and get-realtime-updates**\n```python\nfrom kivy.uix.screenmanager import Screen  # noqa\nfrom sjfirebase.tools.mixin import FirestoreMixin\n\n\nclass MyScreen(Screen, FirestoreMixin):\n    def on_event1(self):\n        # gets a dictionary of data from \"document_id\" if any data and passes\n        # `success` (True/False) and `data` (dict/errorMessage).\n        # always check if success is True before accessing items from data,\n        # or check if data is an instance of dict. Else log the data to see the error message\n        self.get_document(\"individual/document_id\", lambda success, data: print(success, data))\n    \n    def on_event2(self):\n        # everything @on_event1 plus `source` that states where the data should be fetched.\n        # either cache, server or default. cache gets from firebase data stored locally\n        # on the device for offline purposes while server gets from firebase cloud directly.\n        # default can be either cache or cloud depending on your configuration.\n        self.get_document(\"individual/document_id\", lambda success, data: print(success, data), source=\"cache\")\n    \n    def on_event3(self):\n        # gets all document at \"individual\" collection and passes success and data argument.\n        # here, data is a list of dict. before accessing, refer to @on_event1\n        self.get_collection_of_documents(\"individual\", lambda success, data: print(success, data))\n    \n    def on_event4(self):\n        # refer to @on_event2 for \"source\" and @on_event3 for functionality description\n        self.get_collection_of_documents(\"individual\", lambda success, data: print(success, data), source=\"cache\")\n\n    def on_event5(self):\n        # refer to @on_event3 for functionality description. The new thing here is `limit`.\n        # limit is used to limit the amount of data you fetch from firebase and paginate as you go.\n        self.get_pagination_of_documents(\"individual\", 10, lambda success, data: print(success, data))\n\n    def on_event6(self):\n        # listens for document changes and returns a dict of data and location\n        # where the data is coming from. `data`(dict/errorMessage), where(\"Local\"/\"Server\")\n        self.add_document_snapshot_listener(\"individual/document_id\", lambda data, where: print(data, where))\n    \n    def on_event7(self):\n        # same as @on_event6 but gets a list of document with information on whether they were\n        # added, removed or modified\n        self.add_collection_snapshot_listener(\"individual\", lambda data, where: print(data, where))\n```\n\n\n### Python API\n#### ActionCodeSettings\n```python\nclass sjfirebase.jclass.action.ActionCodeSettings\n```\nStructure that contains the required continue/state URL with optional Android and iOS bundle identifiers. \nThe stateUrl used to initialize this class is the link/deep link/fallback url used while constructing the \nFirebase dynamic link.\n\n**methods**\n- `newBuilder`\n##### Visit [ActionCodeSettings Documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/auth/ActionCodeSettings) for more API\n\n#### SJFirebaseAuthEmai\n```python\nclass sjfirebase.jclass.emailauth.SJFirebaseAuthEmail\n```\nThe entry point of the Firebase Authentication SDK.\nFirst, obtain an instance of this class by calling `get_instance`\n\n**methods**\n- check_user_signed_in\n- get_instance\n##### Visit [FirebaseAuth Documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth) for more API\n\n#### SJFirebaseDatabase\n```python\nclass sjfirebase.jclass.database.SJFirebaseDatabase\n```\nThe entry point for accessing a Firebase Database. \nYou can get an instance by calling getInstance. \nTo access a location in the database and read or write data, use `get_ref`\n\n**methods**\n- get_db\n- get_ref\n##### Visit [FirebaseDatabase Documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/database/FirebaseDatabase) for more API\n\n#### SJFirebaseFirestore\n```python\nclass sjfirebase.jclass.firestore.SJFirebaseFirestore\n```\n\n**methods**\n- get_db\n##### Visit [FirebaseFirestore Documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/FirebaseFirestore) for more API\n\n#### SJFirebaseUser\n```python\nclass sjfirebase.jclass.user.SJFirebaseUser\n```\nRepresents a user's profile information in your Firebase project's user database. \nIt also contains helper methods to change or retrieve profile information, \nas well as to manage that user's authentication state.\n\n**methods**\n- get_current_user\n- profile_change_request_builder\n##### Visit [FirebaseUser Documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser) for more API\n\n#### SJFirebaseStorage\n```python\nclass sjfirebase.jclass.user.SJFirebaseStorage\n```\nFirebaseStorage is a service that supports uploading and downloading large objects\nto Google Cloud Storage. Pass a custom instance of FirebaseApp to get_instance which\nwill initialize it with a storage location (bucket) specified via setStorageBucket.\n\nOtherwise, if you call getReference without a FirebaseApp, the FirebaseStorage instance\nwill initialize with the default FirebaseApp obtainable from get_instance. The storage\nlocation in this case will come the JSON configuration file downloaded from the web\n\n**methods**\n- get_instance\n##### Visit [FirebaseStorage Documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/storage/FirebaseStorage) for more API\n\n#### OnCompleteListener\n```python\nclass sjfirebase.jinterface.google\n\nOnCompleteListener\n```\nListener called when a Task completes.\n\n**methods**\n- onComplete\n##### Visit [OnCompleteListener Documentation](https://developers.google.com/android/reference/com/google/android/gms/tasks/OnCompleteListener) for more API\n\n#### ValueEventListener\n```python\nclass sjfirebase.jinterface.firebase.ValueEventListener\n```\n\n**methods**\n- onDataChange\n- onCancelled\n##### Visit [ValueEventListener Documentation](https://firebase.google.com/docs/reference/android/com/google/firebase/database/ValueEventListener) for more API\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplejnius%2Fsj-firebase-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplejnius%2Fsj-firebase-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplejnius%2Fsj-firebase-python/lists"}