Registry / auth-security / streamlit-authenticator

streamlit-authenticator

JSON →
library0.4.2pypypiunverified

Streamlit Authenticator (current version 0.4.2) is a Python library that provides a secure authentication module to manage user access in Streamlit applications. It offers various widgets for login, logout, user registration, password reset, and user detail modification, supporting both local credential management and integration with OAuth2 providers. The library is actively maintained with frequent releases introducing new features and improvements.

pip install streamlit-authenticator
INSTALL
IMPORT
SIG · STREAMLIT-AUTHENTI
S
streamlit-authenticator
auth-securitypythonv0.4.2
Install
17.1s avg
Import
2279ms
Disk
464MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 2.695s · 475.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 17.1s · import 1.862s · 445MB
464MB installed
● package 464MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Authenticate
import streamlit_authenticator as stauth authenticator = stauth.Authenticate(...)
from streamlit_authenticator import Authenticate
The common pattern is to import the module as 'stauth' and then access 'Authenticate' and 'Hasher' classes from it.
Hasher
import streamlit_authenticator as stauth hashed_passwords = stauth.Hasher(passwords).generate()
from streamlit_authenticator.utilities import Hasher
While the utility path might work, the recommended and more stable import pattern is via the top-level 'streamlit_authenticator' module as 'stauth'.

This quickstart demonstrates how to set up basic username/password authentication using `streamlit-authenticator`. It initializes the authenticator with credentials (hardcoded for brevity, but typically loaded from a `config.yaml` file), displays a login widget, and then shows protected content upon successful authentication. It also includes a logout button. For a real application, replace hardcoded `config` with loading from a `config.yaml` and consider storing sensitive keys in environment variables.

import streamlit as st import streamlit_authenticator as stauth import yaml from yaml.loader import SafeLoader # --- User Credentials & Cookie Configuration (typically from config.yaml) --- config = { 'credentials': { 'usernames': { 'john_doe': { 'email': 'john@example.com', 'name': 'John Doe', 'password': 'abc' # Will be hashed if auto_hash is True }, 'rebecca_smith': { 'email': 'rebecca@example.com', 'name': 'Rebecca Smith', 'password': 'def' } } }, 'cookie': { 'expiry_days': 30, 'key': 'random_signature_key_here', 'name': 'my_app_cookie' } } # To simulate loading from file (for demonstration, usually you'd load from actual config.yaml) # In a real app, you would load this from a persistent config.yaml file. # Example: with open('config.yaml') as file: # config = yaml.load(file, Loader=SafeLoader) # Hash passwords only if not already hashed (auto_hash=True by default in Authenticate) # You can pre-hash them explicitly if you wish: # for username, user_data in config['credentials']['usernames'].items(): # user_data['password'] = stauth.Hasher([user_data['password']]).generate()[0] # --- Initialize Authenticator --- authenticator = stauth.Authenticate( config['credentials'], config['cookie']['name'], config['cookie']['key'], config['cookie']['expiry_days'], # api_key=os.environ.get('STREAMLIT_AUTH_API_KEY', None) # For 2FA/email features ) # --- Login Widget --- name, authentication_status, username = authenticator.login('Login', 'main') if authentication_status == False: st.error('Username/password is incorrect') elif authentication_status == None: st.warning('Please enter your username and password') elif authentication_status: # --- Main App Content for Authenticated Users --- authenticator.logout('Logout', 'main') st.write(f'Welcome *{name}*') st.title('Application Content') st.write('This content is only visible to authenticated users.') # Example of accessing user info from session state # st.write(f"Current user: {st.session_state['username']}") # st.write(f"Authentication status: {st.session_state['authentication_status']}")
Debug
Known issues
breakingThe `Authenticate` class constructor parameters changed significantly between versions (e.g., from v0.3.x to v0.4.x). The `credentials` parameter now expects a dictionary or a path to a config file, rather than separate lists for names, usernames, and hashed passwords.
fix
Update your `Authenticate` initialization to pass a single dictionary for `credentials` (or a file path) that includes usernames, names, and passwords. Refer to the latest documentation for the correct structure. For example, `stauth.Authenticate(config['credentials'], ...)` where `config` is loaded from a YAML file.
affects: >=0.4.0
breakingThe `pre_authorized` list was removed from the `Authenticate` class constructor in v0.4.1 and is now handled directly by the `register_user` widget as a parameter.
fix
If you were using `pre_authorized`, remove it from the `Authenticate` constructor and pass it as a parameter when calling `authenticator.register_user(...)` instead.
affects: >=0.4.1
gotchaFor multi-page Streamlit applications, it is crucial to pass the `authenticator` object to each page (e.g., via `st.session_state`) and ensure `key` parameters are unique for widgets across pages to prevent `DuplicateWidgetID` errors.
fix
Store the initialized `authenticator` object in `st.session_state` on your main page and access it from other pages. Always provide unique `key` arguments to all `streamlit-authenticator` widgets in multi-page apps.
affects: All versions
gotchaEnabling two-factor authentication or email features (e.g., for password reset) in v0.4.2 requires registering for a free API key and passing it to the `Authenticate` constructor via the `api_key` parameter or in the config file.
fix
Register for an API key at `stauthenticator.com` and provide it to the `Authenticate` class during initialization, either directly or within your configuration dictionary.
affects: >=0.4.2
Upgrade
Version history
0.4.2latest on PyPI · released Mar 1, 2025
Audit
Dependencies
streamlitrequiredCore framework dependency for building web applications.
extra-streamlit-componentsrequiredUsed for certain UI components and functionality, especially in older versions.
pyyamlrequiredRequired for loading/saving credentials from/to YAML configuration files.
Agent activity
27 hits · last 30 days
node
22
OpenAI (training)
1
Resources
streamlit-authenticator — pip install streamlit-authenticator · libregistry