Skip to main content

streamlit-infinite-pages

Streamlit wrapper to make creating multi page apps easier.

Install

pip install streamlit-infinite-pages

Features

  • Simpler multi-page apps
  • Control traceback
    • Fix security issue with base streamlit that leaks code/traceback into app
  • Customizable authentication flow
  • Per page authorization/access control
  • Add simple branding/metadata integration
  • Keyboard shortcuts
  • Custom CSS / JS
  • Add various stateful elements

Tutorial

One simple app

import streamlit as st
from sip import App, Page

def home_page() -> None:
    st.markdown("# Home")


app = App(
    name="Demo App",
    icon="🚀",
)

app.add(Page(name="Home", main=home_page))

# `index` is the default page
app.run(index="Home")

Multi page app

import streamlit as st
from sip import App, Page

def home_page() -> None:
    st.markdown("# Home")

def other_page() -> None:
    st.markdown("# Other page")

app = App(
    name="Demo App",
    icon="🚀",
)

app.add(Page(name="Home", main=home_page))

app.add(Page(name="Other", main=other_page))

# alternatively, you can add pages as a list
# app.add(
#     [
#         Page(name="Home", main=home_page),
#         Page(name="Other", main=other_page),
#     ],
# )

app.run(index="Home")

Control output traceback

This app will show the default traceback.

import streamlit as st
from sip import App, Page

def zero_division_error() -> None:
    st.write(1 / 0)

app = App(
    name="Demo App",
    icon="🚀",
)

app.add(Page(name="Error", main=zero_division_error))

app.run(index="Error")

And this one will hide it. You can substitute whatever handler logic you want in here.

import streamlit as st
from sip import App, Page

def zero_division_error() -> None:
    st.write(1 / 0)

def hidden_traceback(e: Exception) -> None:
    st.toast(":red[Error]")

app = App(
    name="Demo App",
    icon="🚀",
    traceback_handler=hidden_traceback,
)

app.add(Page(name="Error", main=zero_division_error))

app.run(index="Error")

Add authentication flow

You can replace the authentication handler with whatever function you want, integrating cognito, auth0, keycloak, etc. You'll can store the token and user in the session state if need be.

import streamlit as st
from sip import App, Page

def home_page() -> None:
    st.markdown("# Home")

# should return true if authentication succeeded, false if failed
# otherwise if no input submitted none
def authentication_handler() -> bool | None:
    super_secret_password = "qwerty"
    password_input = st.text_input(label="Enter password:", type="password")
    if password_input:
        return password_input == super_secret_password
    else:
        return None

app = App(
    name="Demo App",
    icon="🚀",
    auth_handler=authentication_handler,
)

app.add(Page(name="Home", main=home_page))

app.run(index="Home")

Per page authorization

Of course, the actual authentication should be more secure. You could probably replace the admin_only_check function with user groups after a JWT is validated or something.

import streamlit as st
from sip import App, Page

users = {
    "alice": {
        "password": "ilikebob",
        "access": "basic",
    },
    "bob": {
        "password": "bobrocks",
        "access": "admin",
    },
}

def home_page() -> None:
    st.markdown("# Home")

def admin_only_page() -> None:
    st.markdown("This page is only accessible to admins.")

def admin_only_check() -> bool:
    return st.session_state["access"] == "admin"

# should return true if authentication succeeded, false if failed
# otherwise if no input submitted none
def authentication_handler() -> bool | None:
    username_input = st.text_input(label="Enter username:")
    password_input = st.text_input(label="Enter password:", type="password")
    if username_input and password_input:
        if not (username_input in users.keys()):
            return False
        else:
            if password_input == users[username_input]["password"]:
                st.session_state["user"] = username_input
                st.session_state["access"] = users[username_input]["access"]
                return True
            else:
                return False
    else:
        return None


app = App(
    name="Demo App",
    icon="🚀",
    auth_handler=authentication_handler,
    initial_session_state={"access": None},
)

app.add(
    Page(name="Home", main=home_page),
)

app.add(
    Page(
        name="only for admins",
        main=admin_only_page,
        accessible=admin_only_check,
    )
)

app.run(index="Home")

Metadata

Release files for streamlit-infinite-pages 0.1.1

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-infinite-pages 0.1.1
File Size Uploaded Provenance
streamlit_infinite_pages-0.1.1.tar.gz 4.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-infinite-pages 0.1.1
File Interpreter ABI Platform
streamlit_infinite_pages-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / streamlit_infinite_pages-0.1.1.tar.gz

Download URL streamlit_infinite_pages-0.1.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ccb9f230b4e37c7f49f6ea0f58c9f490b3556b8c072f4caaa8b2fc10986c71d2
BLAKE2b-256 checksum
How to use checksums
d4b9739c5f436915dc8f477899e73392f4a4d84683b17ee76cf55700cf60b710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.2.0

Release files / streamlit_infinite_pages-0.1.1-py3-none-any.whl

Download URL streamlit_infinite_pages-0.1.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1945cd30e9e7d235f95efc17b98cf6af299f8b004da28f474255f61f1416768a
BLAKE2b-256 checksum
How to use checksums
3c8c973e084fe6cc36e0b3184819cb878ebc4deb1f2ddfba9137dfc31b257f17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.2.0

Security for streamlit-infinite-pages 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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