Skip to main content

A Python package for creating subscription Streamlit apps

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

st_paywall-1.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

st_paywall-1.0.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file st_paywall-1.0.2.tar.gz.

File metadata

  • Download URL: st_paywall-1.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for st_paywall-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8f8da0dc643afd19147291924d48a9588e44a111c1105e56db3bfecb58a8f58f
MD5 dacab4d28becc0c7842a1580cc24464e
BLAKE2b-256 f7fd3f47a075d909a10f455b3c9f0c18d26181ee342ae61327cf08da2d5aea87

See more details on using hashes here.

File details

Details for the file st_paywall-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: st_paywall-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for st_paywall-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79230f25ba4804aa3a53f8aba77edca20f36a005a740486a0b8718fb60a50b98
MD5 519d2d5bf8da4c213f7f87df89e1e469
BLAKE2b-256 135762c32731867b5068be1b430543cea605a0ad3379f55d2956da9d7920771e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page