Skip to content

tylerjrichards/st-paywall

Repository files navigation

Releases

Streamlit App

Author: @tylerjrichards

Kind consultant: @blackary

st-paywall 🎈

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!

Installation

pip install st-paywall

Quick Start

  1. Set up Streamlit's native authentication in your app's secrets.toml file
  2. Add your payment provider configuration (Stripe or Buy Me A Coffee)
  3. 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}")

Configuration

Create a .streamlit/secrets.toml file with your payment provider settings:

For Stripe:

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_..."

For Buy Me A Coffee:

payment_provider = "bmac"
bmac_api_key = "ey..."
bmac_link = "https://www.buymeacoffee.com/..."

Customization

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
)

Example App

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!")

Documentation

For full documentation, visit st-paywall.readthedocs.io

License

MIT

Feedback:

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.

About

A python package for creating subscription Streamlit apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages