Streamlit Deeplinker
Set state deep in an application with ease.
Make them navigatable through your broswer history, and shareable with other people through an URL.
Install
Install with your favorite package manager
Poetry: poetry add streamlit-deeplinker
Pip: pip install streamlit-deeplinker
And then you can start creating deeplink applications like the following:
from streamlit_deeplinker import deeplinks, set_deeplink
from pydantic import BaseModel
class StateA(BaseModel):
name: str
async def page_a(state: StateA):
st.write(f"Hello {state.name}")
if st.button("Go back"):
set_deeplink(None)
@deeplinks(
deeplinks={
StateA: page_a,
}
)
def app():
st.title("Deeplink Example")
st.write("This is the landing page. You can navigate to other pages using the button bellow.")
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.
Each pydantic model expects an associated function which can either be an async function or not. Then the .start() method will figure out if it needs to run the application through asyncio.
@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():
...
Metadata
Release files for streamlit-deeplinker 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| streamlit_deeplinker-0.1.2.tar.gz | 7.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_deeplinker-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.0 kB
Release files / streamlit_deeplinker-0.1.2.tar.gz
| Download URL | streamlit_deeplinker-0.1.2.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aec5941033e376d3194169b38120bfd0b25534e7f7365dc6563c12a046119750
|
|
BLAKE2b-256 checksum How to use checksums |
bbaf0c47eba6de50ad4570a03f96529b0a386f91d44948ebe77298f952e291a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.9 Linux/6.5.0-1017-azure
|
Release files / streamlit_deeplinker-0.1.2-py3-none-any.whl
| Download URL | streamlit_deeplinker-0.1.2-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2dd4fe82e19cb5f019b0525041ea0ef07d12da904db248d813b584b2472dc736
|
|
BLAKE2b-256 checksum How to use checksums |
e0a02a32beecc674859c51bb424c469d9898a03f199d91340a5d3cb1d7d7dc14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.9 Linux/6.5.0-1017-azure
|
Security for streamlit-deeplinker 0.1.2
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.