streamlit_supabase_auth_ui
Seamless Supabase authentication for seamless Streamlit apps
Purpose and Inspiration
Streamlit is a popular backend-to-frontend app development framework for python, and over the years several solutions have been developed to tackle user authentication and management for Streamlit apps.
The most popular of them, streamlit-authenticatorand streamlit_login_auth_ui, although offering several advanced functionalities and dynamic UIs, lack a reliable backend, database-centered user management (which is generally performed through local files).
We decided to build a new authentication UI, based on Gauri Prabhakar's login interface, that combines the power of SupabasePostgreSQL databases with the seamless frontend components from Streamlit, connecting it also to the e-mail notifications service offered by Courier .
The UI has login, user registration, password reset and 'forgot password' functionalities, as well as a logout one.
So, let's get started!🚀
Third party services
1. Supabase
We will need a Supabase account to build a project, retrieve its URL and ANON key and create a user_authentication database, that will connect our UI to the backend, database-centered user-management.
In order to do that, we:
- Create a Supabase account
- Go to our dashboard
- Create a new project
- Go to
Project Settings > APIand copyURLunderProject URLandanon publickey underProject API Keys - Copy the URL to
supa_urland the ANON key tosupa_keyin.streamlit/secrets.toml - Open SQL editor on Supabase and execute the following command:
CREATE TABLE user_authentication (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
username VARCHAR(255) DEFAULT NULL,
password VARCHAR(255) DEFAULT NULL,
email VARCHAR(255) DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP DEFAULT NOW(),
last_login FLOAT DEFAULT 0,
last_logout FLOAT DEFAULT 0
);
2. Courier
We want to send email notifications basically for two reasons:
- Welcome our new users upon registration
- Send them reset passwords when they want to change their old/lost password
To do so, we use the already mentioned Courier, and so we need to:
- Sign up to Courier
- Create a new workspace
- Enable an e-mail service provider. The easiest and cheapest choice is Gmail: you only need to specify the Gmail account for which you want to activate the service, which will also be one that will send all the emails.
- Retrieve the authorization token from
Settings > API Keys - Copy the authorization token and place it under
courier_auth_tokenin .streamlit/secrets.toml
Create your application
1. Build from source
We now want to create our Streamlit application with Supabase authentication and user management, and, in order to do so, we:
- Clone this repository and go inside it:
git clone https://github.com/AstraBert/streamlit_supabase_auth_ui.git
cd streamlit_supabase_auth_ui
- Create a python virtual environment and activate it:
python3 -m venv streamlit-app
source streamlit-app/bin/activate
- Install all the required dependencies:
python3 -m pip install -r requirements.txt
- Modify
.streamlit/secrets.tomlwith the Supabase project URL (supa_url), Supabase project ANON key (supa_key) and Courier authentication token (courier_auth_token) we retrieved beforehand - Run the application:
python3 -m streamlit run app.py
You can obviously customize the Streamlit application as much as you want, you will only need to integrate this peace of code to make the Supabase-based auth to work:
import streamlit as st
from .streamlit_supabase_auth_ui.widgets import __login__
__login__obj = __login__(auth_token = st.secrets["courier_auth_token"],
company_name = "YOUR-ORG-NAME",
width = 200, height = 250,
logout_button_name = 'Logout', hide_menu_bool = False,
hide_footer_bool = False,
lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')
LOGGED_IN= __login__obj.build_login_ui()
if LOGGED_IN == True:
### Your Streamlit app here!
2. Get PyPi package
We made streamlit-supabase-auth-ui also a python package available on PyPi, that you can find here.
To get it, it is sufficient to run:
python3 -m pip install streamlit-supabase-auth-ui
And the installation process will take care of mounting all the necessary dependencies✅
You can then simply import the package in your code:
import streamlit as st
from streamlit_supabase_auth_ui.widgets import __login__
__login__obj = __login__(auth_token = st.secrets["courier_auth_token"],
company_name = "YOUR-ORG-NAME",
width = 200, height = 250,
logout_button_name = 'Logout', hide_menu_bool = False,
hide_footer_bool = False,
lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')
Live demo
Find a live demo on HuggingFace Spaces.
Contributions
Contributions are more than welcome! See contribution guidelines for more information :)
Funding
If you found this project useful, please consider to fund it and make it grow: let's support open-source together!😊
License and rights of usage
This project is provided under MIT license: it will always be open-source and free to use.
If you use this project, please cite the author: Astra Clelia Bertelli
Metadata
Release files for streamlit-supabase-auth-ui 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit_supabase_auth_ui-0.2.0.tar.gz | 12.0 kB | Without provenance | Details for streamlit_supabase_auth_ui-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_supabase_auth_ui-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for streamlit_supabase_auth_ui-0.2.0-py3-none-any.whl |
Total release size: 22.1 kB
Release files / streamlit_supabase_auth_ui-0.2.0.tar.gz
| Download URL | streamlit_supabase_auth_ui-0.2.0.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
348c0035b678977974958c0dce062d4012ff812b9f8f055e35cd2455a118be04
|
|
BLAKE2b-256 checksum How to use checksums |
ed68024ebca1508dc551a7dcb470359ebd041ad10c97ab0eef52b14f2c6602f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / streamlit_supabase_auth_ui-0.2.0-py3-none-any.whl
| Download URL | streamlit_supabase_auth_ui-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92a19b353850afbe1266ecbaf36cb9b7be6ff6b8b6b9651b23d1ab91a0f19515
|
|
BLAKE2b-256 checksum How to use checksums |
6a5f318f9e2c78acd3f4c69506e1dacc11f0c9895149514c63334cdec07837c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for streamlit-supabase-auth-ui 0.2.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.