Skip to main content

A package that makes it possible to add deeplinks in a streamlit application

Project description

Streamlit Deeplink

Set state deep in an application with ease.

Make them navigatable through your broswer history, and shareable with other people through an URL.

from streamlit_deeplinker import deeplinks, set_deeplink
from pydantic import BaseModel

class StateA(BaseModel):
    name: str

def page_a(state: StateA):
    ...

@deeplinks(
    deeplinks={ # type: ignore
        StateA: page_a,
    }
)
def app():
    st.title("Deeplink Example")

    st.write("This is the landing page. You can navigate to other pages using the sidebar.")

    st.button("Next"):
        set_deeplink(StateA("World"))

app.start()

Motivation

Streamlit is an awesome technology to get Python applications up and running with an UI. However thier "run from top to bottom" structure can lead lead to issues when setting state deep down in the applications. Potentially making some state getting lost, or leading to a slow application.

Therefore, this package makes it possible to create dedicated pages for a given state. Leading to faster applications and less complex applications.

Usage

The streamlit_deeplinkerer works by routing the user state to differnet functions.

The state is assumed to be defined as pydantic models, as they will be encoded and decoded as url params.

[!WARNING]
Encoding data in the URL params can lead to issues for large payload, as web browsers have different max URL lengths. Therefore, try to keep the state as light weight as possible.

Each pydantic model expects an associated function which.

@deeplinks(
    deeplinks={ # type: ignore
        StateA: page_a,
        StateB: page_b,
        ...
    }
)
def initial_page():
    ...

Sidebar

You can also configure the sidebar in the deeplinks call, and then the router will make sure it is rendered for all the different deeplinks.

from streamlit.delta_generator import DeltaGenerator

def render_sidebar(sidebar: DeltaGenerator):
    sidebar.title("Hello")

@deeplinks(
    deeplinks={ # type: ignore
        StateA: page_a,
        StateB: page_b,
        ...
    },
    sidebar=render_sidebar
)
def initial_page():
    ...

Streamlit Config

Since the deeplink router do not run the initial page on deeplinks will it not be the best place to set streamlit configs. Therefore, is it possible to pass a config param to the deeplinks method.

from streamlit_deeplinker import StreamlitConfig, deeplinks

@deeplinks(
    deeplinks={ # type: ignore
        StateA: page_a,
        StateB: page_b,
        ...
    },
    config=StreamlitConfig(
        title="My awesome application",
        icon=":book:",
        layout="wide"
    )
)
def initial_page():
    ...

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

streamlit_deeplinker-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

streamlit_deeplinker-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_deeplinker-0.1.0.tar.gz.

File metadata

  • Download URL: streamlit_deeplinker-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.9 Linux/6.5.0-1017-azure

File hashes

Hashes for streamlit_deeplinker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c82a6033eb0aa0eba435de5364ef06a821fb3e20a80ed3a8e734a572c6f803ca
MD5 35ef81d2c267ac3180dd3c006affe006
BLAKE2b-256 ec9dc43032e5380ebb22c5feaa8215e3728d091f52c1c9ef93edc21d7fe34f97

See more details on using hashes here.

File details

Details for the file streamlit_deeplinker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_deeplinker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d415e0db3f8a11bdf26c7afebde7f59f1f114aed2b9e281d3f285c9a0a7075ff
MD5 24c19893072a182b74bab33effadc4a7
BLAKE2b-256 ef9f3b5666cf69b489d12419ce15014d93128860bc951fdb36d6e8b338198195

See more details on using hashes here.

Supported by

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