Skip to main content

Streamlit-Authenticator Downloads

A secure authentication module to validate user credentials in a Streamlit application.

Installation

Streamlit-Authenticator-Sheets is distributed via PyPI:

pip install streamlit-authenticator-sheets

Example

Using Streamlit-Authenticator_Sheets is as simple as importing the module and calling it to verify your predefined users' credentials.

import streamlit as st
import streamlit_authenticator as stauth

1. Hashing Passwords

  • Initially define your users' names, usernames, plain text passwords, and reauthentication cookie settings in a YAML configuration file.
credentials:
  names: ['John Smith', 'Rebecca Briggs']
  usernames: ['jsmith', 'rbriggs']
  passwords: ['123', '456'] # To be replaced with hashed passwords
cookie:
  name: 'some_cookie_name'
  key: 'some_signature_key'
  expiry_days: 30
  • Then use the Hasher module to convert the plain text passwords to hashed passwords.
hashed_passwords = stauth.Hasher(['123', '456']).generate()

Finally replace the plain text passwords in the configuration file with the hashed passwords.

2. Creating Login Widget

  • Subsequently import the configuration file into your script to create an authentication object. Here you will need to enter a name for the JWT cookie that will be stored on the client's browser and used to reauthenticate the user without re-entering their credentials. In addition, you will need to provide any random key to be used to hash the cookie's signature. Finally, you will need to specify the number of days to use the cookie for, if you do not require passwordless reauthentication, you may set this to 0.
with open('../config.yaml') as file:
    config = yaml.load(file, Loader=SafeLoader)

authenticator = stauth.Authenticate(
    config['credentials']['names'],
    config['credentials']['usernames'],
    config['credentials']['passwords'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days']
)
  • Then finally render the login module as follows. Here you will need to provide a name for the login form, and specify where the form should be located i.e. main body or sidebar (will default to main body).
name, authentication_status, username = authenticator.login('Login', 'main')

3. Authenticating Users

  • You can then use the returned name and authentication status to allow your verified user to proceed to any restricted content. In addition, you have the ability to add an optional logout button at any location on your main body or sidebar (will default to main body).
if authentication_status:
    authenticator.logout('Logout', 'main')
    st.write(f'Welcome *{name}*')
    st.title('Some content')
elif authentication_status == False:
    st.error('Username/password is incorrect')
elif authentication_status == None:
    st.warning('Please enter your username and password')
  • Should you require access to the persistent name, authentication status, and username variables, you may retrieve them through Streamlit's session state using st.session_state['name'], st.session_state['authentication_status'], and st.session_state['username']. This way you can use Streamlit-Authenticator to authenticate users across multiple pages.
if st.session_state['authentication_status']:
    authenticator.logout('Logout', 'main')
    st.write(f'Welcome *{st.session_state["name"]}*')
    st.title('Some content')
elif st.session_state['authentication_status'] == False:
    st.error('Username/password is incorrect')
elif st.session_state['authentication_status'] == None:
    st.warning('Please enter your username and password')

Or prompt an unverified user to enter a correct username and password.

Please note that logging out will revert the authentication status to None and will delete the associated reauthentication cookie as well.

Credits

Release files for streamlit-authenticator-sheets 0.1.7

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

Source distribution (sdist)

Source distribution for streamlit-authenticator-sheets 0.1.7
File Size Uploaded
streamlit_authenticator_sheets-0.1.7.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-authenticator-sheets 0.1.7
File Interpreter ABI Platform
streamlit_authenticator_sheets-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / streamlit_authenticator_sheets-0.1.7.tar.gz

Download URL streamlit_authenticator_sheets-0.1.7.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e0c099cdc5eb9d4e2b08558196e87db5eca43507c0df6e4889ca18c52ee15f2c
BLAKE2b-256 checksum
How to use checksums
88859a8b1b2406b3b62ad72bee8b04219769ca8e9e41b37abe46673858319cf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / streamlit_authenticator_sheets-0.1.7-py3-none-any.whl

Download URL streamlit_authenticator_sheets-0.1.7-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6134d72e4eac89624d1f067573d758208183e3456d99ad22e42f8b07966f3667
BLAKE2b-256 checksum
How to use checksums
6b49fede786fdd1e4ddf29a1d70861bd8e850ff5f01d83bca089967c28e65a8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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