Author: @tylerjrichards
Kind consultant: @blackary
A Python package for creating paywalled Streamlit apps!
I made st-paywall so data scientists and LLM developers can create small businesses around their Streamlit apps. Every week I see dozens of new incredible apps built in Streamlit that are adored by users, but eventually shut down or moved off of Streamlit as payment integration is too hard. This is my attempt at a dead-simple API around payments, abstracting it away into a single function (add_auth
). Enjoy!
pip install st-paywall
- Set up Streamlit's native authentication in your app's secrets.toml file
- Add your payment provider configuration (Stripe or Buy Me A Coffee)
- Import and use
add_auth()
in your app
import streamlit as st
from st_paywall import add_auth
st.title("My Subscription App")
# Handle Streamlit's native authentication
if not st.experimental_user.is_logged_in:
if st.button("Log in using Streamlit's native authentication"):
st.login()
else:
# Add subscription check for logged-in users
add_auth()
# Your app code here - only runs for subscribed users
st.write("Welcome, subscriber!")
st.write(f"Your email is: {st.experimental_user.email}")
Create a .streamlit/secrets.toml
file with your payment provider settings:
payment_provider = "stripe"
testing_mode = true # Set to false for production
stripe_api_key_test = "sk_test_..."
stripe_api_key = "sk_live_..."
stripe_link = "https://buy.stripe.com/..."
stripe_link_test = "https://buy.stripe.com/test_..."
payment_provider = "bmac"
bmac_api_key = "ey..."
bmac_link = "https://www.buymeacoffee.com/..."
The add_auth()
function accepts several parameters to customize its behavior:
add_auth(
required=True, # Stop the app if user is not subscribed
show_redirect_button=True, # Show the subscription button
subscription_button_text="Subscribe Now!", # Custom button text
button_color="#FF4B4B", # Button color (CSS color value)
use_sidebar=True # Show button in sidebar vs main section
)
import streamlit as st
from st_paywall import add_auth
st.title("My Subscription App")
if not st.experimental_user.is_logged_in:
st.write("Please log in to access this app")
if st.button("Log in"):
st.login()
else:
add_auth(required=True)
st.write("Welcome to the premium content!")
For full documentation, visit st-paywall.readthedocs.io
MIT
If you have feedback about this package, please reach out to me on twitter or file an issue in this repo and I will do my best to help you out.