# firebase_user
This package is meant as a convenient client interface for the firebase REST API.
It doesn't use the firebase-admin sdk and doesn't require any admin credentials.
Only uses the firebase app config object of your app which can safely be exposed in the client codebase.
Supports Auth, Firestore and Storage for a quick yet powerful decentralized user management on the client side.
You need to setup a firebase project via the firebase console in order to use it.
Don't forget to set up proper security rules in firebase to prevent a user getting access to other users' data content.
## Installation
```bash
$ pip install firebase-user
```
## Usage
```python
from firebase_user import FirebaseClient
import json
#Get the json app config of your project
with open('app_config.json','r') as f:
config=json.load(f)
#Initialize the client with it
client=FirebaseClient(config)
#----------------Authentication-----------------
#Sign up for a new account
client.auth.sign_up("email","password")
#or sign in
client.auth.sign_in("email","password")
#Check authentication success
print(client.auth.authenticated)
# True
#Additional auth features
client.auth.change_password("new_password")
client.auth.refresh_token() #This method is called automatically in case the initial token expired
client.auth.delete_user()
#---------------- Firestore -----------------
#Get the user's data from firestore (ie. the document with user's email adress as name in the 'users' collection)
data=client.firestore.get_user_data()
#Make changes (nested attribute-style access supported)
data.age=34
data.hobbies=["Guitar playing","Basketball"]
#Dump changes to firestore
client.firestore.set_user_data(data)
#You may also read and write to a chosen document in a given collection (provided the user has permission to access it)
data=client.firestore.get_document(collection,document)
client.firestore.set_document(collection,document,data)
#Using a firestore listener thread to detect changes in a document (optional callback called when a change is detected)
def callback(document):
print(f"Document changed: {document}")
listener=client.firestore.listener(collection,document,interval=1,timeout=3600,callback=callback)
listener.start() # start the listening thread
print(listener.is_listening) #True
data=listener.get_data() # waits until a change is detected and captures it
listener.stop() #stop listening
#----------------- Storage ------------------
#list files in the user's storage (includes files metadata)
files=client.storage.list_files()
#upload / download a file from / to cloud storage
client.storage.upload_file(local_file="./folder/file.txt",remote_file="folder/file.txt")
client.storage.download_file(remote_file="folder/file.txt",local_file="./folder/file.txt")
#load / dump a whole folder from / to the cloud storage (will overwrite the local / remote folder as a whole)
client.storage.load_folder("./folder")
client.storage.dump_folder("./folder")
#log out
client.auth.log_out()
print(client.auth.authenticated)
# False
```
## License
This project is available under MIT license. Please see the LICENSE file for more details.
## Contributions
Contributions are welcome. Please open an issue or a pull request to suggest changes or additions.
## Contact
For any questions or support requests, please contact Baptiste Ferrand at the following address: bferrand.maths@gmail.com.
Raw data
{
"_id": null,
"home_page": "https://github.com/B4PT0R/firebase_user",
"name": "firebase-user",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Baptiste Ferrand",
"author_email": "bferrand.maths@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/37/92/3c3ea524d3bfa7455e69419a843a3ce799c493cc8bd458d9a339c38b4bf2/firebase_user-0.0.21.tar.gz",
"platform": null,
"description": "\n# firebase_user\n\nThis package is meant as a convenient client interface for the firebase REST API.\nIt doesn't use the firebase-admin sdk and doesn't require any admin credentials.\nOnly uses the firebase app config object of your app which can safely be exposed in the client codebase.\nSupports Auth, Firestore and Storage for a quick yet powerful decentralized user management on the client side.\n\nYou need to setup a firebase project via the firebase console in order to use it.\nDon't forget to set up proper security rules in firebase to prevent a user getting access to other users' data content. \n\n## Installation\n\n```bash\n$ pip install firebase-user\n```\n\n## Usage\n\n```python\nfrom firebase_user import FirebaseClient\nimport json\n\n#Get the json app config of your project\nwith open('app_config.json','r') as f:\n config=json.load(f)\n\n#Initialize the client with it\nclient=FirebaseClient(config)\n\n#----------------Authentication-----------------\n\n#Sign up for a new account\nclient.auth.sign_up(\"email\",\"password\")\n#or sign in\nclient.auth.sign_in(\"email\",\"password\")\n\n#Check authentication success\nprint(client.auth.authenticated)\n# True\n\n#Additional auth features\nclient.auth.change_password(\"new_password\")\nclient.auth.refresh_token() #This method is called automatically in case the initial token expired\nclient.auth.delete_user()\n\n#---------------- Firestore -----------------\n\n#Get the user's data from firestore (ie. the document with user's email adress as name in the 'users' collection) \ndata=client.firestore.get_user_data()\n\n#Make changes (nested attribute-style access supported)\ndata.age=34\ndata.hobbies=[\"Guitar playing\",\"Basketball\"]\n\n#Dump changes to firestore\nclient.firestore.set_user_data(data)\n\n#You may also read and write to a chosen document in a given collection (provided the user has permission to access it)\ndata=client.firestore.get_document(collection,document)\nclient.firestore.set_document(collection,document,data)\n\n#Using a firestore listener thread to detect changes in a document (optional callback called when a change is detected)\ndef callback(document):\n print(f\"Document changed: {document}\")\n\nlistener=client.firestore.listener(collection,document,interval=1,timeout=3600,callback=callback)\nlistener.start() # start the listening thread\nprint(listener.is_listening) #True\ndata=listener.get_data() # waits until a change is detected and captures it\nlistener.stop() #stop listening\n\n#----------------- Storage ------------------\n\n#list files in the user's storage (includes files metadata)\nfiles=client.storage.list_files()\n\n#upload / download a file from / to cloud storage\nclient.storage.upload_file(local_file=\"./folder/file.txt\",remote_file=\"folder/file.txt\")\nclient.storage.download_file(remote_file=\"folder/file.txt\",local_file=\"./folder/file.txt\")\n\n#load / dump a whole folder from / to the cloud storage (will overwrite the local / remote folder as a whole)\nclient.storage.load_folder(\"./folder\")\nclient.storage.dump_folder(\"./folder\")\n\n#log out\nclient.auth.log_out()\nprint(client.auth.authenticated)\n# False\n\n```\n\n## License\n\nThis project is available under MIT license. Please see the LICENSE file for more details.\n\n## Contributions\n\nContributions are welcome. Please open an issue or a pull request to suggest changes or additions.\n\n## Contact\n\nFor any questions or support requests, please contact Baptiste Ferrand at the following address: bferrand.maths@gmail.com.\n",
"bugtrack_url": null,
"license": "",
"summary": "Client interface for the firebase REST API.",
"version": "0.0.21",
"project_urls": {
"Homepage": "https://github.com/B4PT0R/firebase_user"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c22a92e1658b9e775fdb2963a6fb9dcd34e75c438e6b7ff5d8509ac39b2bb369",
"md5": "fb8aa461947086507f53f747566524d4",
"sha256": "16ff9e79e7796b95238c96b1a11f04442154298f93b114dcdac9975d060e8571"
},
"downloads": -1,
"filename": "firebase_user-0.0.21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fb8aa461947086507f53f747566524d4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8873,
"upload_time": "2024-02-05T22:14:49",
"upload_time_iso_8601": "2024-02-05T22:14:49.255491Z",
"url": "https://files.pythonhosted.org/packages/c2/2a/92e1658b9e775fdb2963a6fb9dcd34e75c438e6b7ff5d8509ac39b2bb369/firebase_user-0.0.21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "37923c3ea524d3bfa7455e69419a843a3ce799c493cc8bd458d9a339c38b4bf2",
"md5": "c29eb43089b6c72bf9fef6a32a582cf1",
"sha256": "3418f7e563bf707fc51632547aabb0b7fc5d342b57082983438d4572f321719c"
},
"downloads": -1,
"filename": "firebase_user-0.0.21.tar.gz",
"has_sig": false,
"md5_digest": "c29eb43089b6c72bf9fef6a32a582cf1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 9941,
"upload_time": "2024-02-05T22:14:51",
"upload_time_iso_8601": "2024-02-05T22:14:51.545526Z",
"url": "https://files.pythonhosted.org/packages/37/92/3c3ea524d3bfa7455e69419a843a3ce799c493cc8bd458d9a339c38b4bf2/firebase_user-0.0.21.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-05 22:14:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "B4PT0R",
"github_project": "firebase_user",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "firebase-user"
}