Skip to main content

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

$ pip install firebase-user

Usage

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.

Metadata

Release files for firebase-user 0.0.21

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

Source distribution (sdist)

Source distribution for firebase-user 0.0.21
File Size Uploaded
firebase_user-0.0.21.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for firebase-user 0.0.21
File Interpreter ABI Platform
firebase_user-0.0.21-py3-none-any.whl Python 3 none any Details

Total release size: 18.8 kB

Release files / firebase_user-0.0.21.tar.gz

Download URL firebase_user-0.0.21.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3418f7e563bf707fc51632547aabb0b7fc5d342b57082983438d4572f321719c
BLAKE2b-256 checksum
How to use checksums
37923c3ea524d3bfa7455e69419a843a3ce799c493cc8bd458d9a339c38b4bf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / firebase_user-0.0.21-py3-none-any.whl

Download URL firebase_user-0.0.21-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16ff9e79e7796b95238c96b1a11f04442154298f93b114dcdac9975d060e8571
BLAKE2b-256 checksum
How to use checksums
c22a92e1658b9e775fdb2963a6fb9dcd34e75c438e6b7ff5d8509ac39b2bb369
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.21 This release

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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