Registry /
auth-security / streamlit-authenticator
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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 2.695s · 475.3MB
glibcpy 3.10–3.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']}")
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.