streamlit-deeplinker


Namestreamlit-deeplinker JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryA package that makes it possible to add deeplinks in a streamlit application
upload_time2024-04-16 06:41:06
maintainerNone
docs_urlNone
authorMats E. Mollestad
requires_python<4.0,>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```python
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_deeplinker`er 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 can either be an `async` function or not. Then the `.start()` method will figure out if it needs to run the application through `asyncio`.

```python
@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.


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

```python
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():
    ...
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "streamlit-deeplinker",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Mats E. Mollestad",
    "author_email": "mats@mollestad.no",
    "download_url": "https://files.pythonhosted.org/packages/bb/af/0c47eba6de50ad4570a03f96529b0a386f91d44948ebe77298f952e291a4/streamlit_deeplinker-0.1.2.tar.gz",
    "platform": null,
    "description": "# Streamlit Deeplinker\n\nSet state deep in an application with ease. \n\nMake them navigatable through your broswer history, and shareable with other people through an URL.\n\n## Install\nInstall with your favorite package manager\n\n**Poetry**: `poetry add streamlit-deeplinker`\n\n**Pip**: `pip install streamlit-deeplinker`\n\nAnd then you can start creating deeplink applications like the following:\n\n```python\nfrom streamlit_deeplinker import deeplinks, set_deeplink\nfrom pydantic import BaseModel\n\nclass StateA(BaseModel):\n    name: str\n\nasync def page_a(state: StateA):\n    st.write(f\"Hello {state.name}\")\n\n    if st.button(\"Go back\"):\n        set_deeplink(None)\n\n@deeplinks(\n    deeplinks={\n        StateA: page_a,\n    }\n)\ndef app():\n    st.title(\"Deeplink Example\")\n\n    st.write(\"This is the landing page. You can navigate to other pages using the button bellow.\")\n\n    st.button(\"Next\"):\n        set_deeplink(StateA(\"World\"))\n\napp.start()\n```\n\n## Motivation\nStreamlit is an awesome technology to get Python applications up and running with an UI.\nHowever 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.\n\nTherefore, this package makes it possible to create dedicated pages for a given state. Leading to faster applications and less complex applications.\n\n\n## Usage\n\nThe `streamlit_deeplinker`er works by routing the user state to differnet functions.\n\nThe state is assumed to be defined as `pydantic` models, as they will be encoded and decoded as url params.\n\n> [!WARNING]  \n> 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.\n\nEach `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`.\n\n```python\n@deeplinks(\n    deeplinks={ # type: ignore\n        StateA: page_a,\n        StateB: page_b,\n        ...\n    }\n)\ndef initial_page():\n    ...\n```\n\n\n### Sidebar\n\nYou can also configure the sidebar in the `deeplinks` call, and then the router will make sure it is rendered for all the different deeplinks.\n\n\n```python\nfrom streamlit.delta_generator import DeltaGenerator\n\ndef render_sidebar(sidebar: DeltaGenerator):\n    sidebar.title(\"Hello\")\n\n@deeplinks(\n    deeplinks={ # type: ignore\n        StateA: page_a,\n        StateB: page_b,\n        ...\n    },\n    sidebar=render_sidebar\n)\ndef initial_page():\n    ...\n```\n\n\n### Streamlit Config\n\nSince 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.\n\n```python\nfrom streamlit_deeplinker import StreamlitConfig, deeplinks\n\n@deeplinks(\n    deeplinks={ # type: ignore\n        StateA: page_a,\n        StateB: page_b,\n        ...\n    },\n    config=StreamlitConfig(\n        title=\"My awesome application\",\n        icon=\":book:\",\n        layout=\"wide\"\n    )\n)\ndef initial_page():\n    ...\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A package that makes it possible to add deeplinks in a streamlit application",
    "version": "0.1.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e0a02a32beecc674859c51bb424c469d9898a03f199d91340a5d3cb1d7d7dc14",
                "md5": "77a86695abe30412a4a6b36345113e18",
                "sha256": "2dd4fe82e19cb5f019b0525041ea0ef07d12da904db248d813b584b2472dc736"
            },
            "downloads": -1,
            "filename": "streamlit_deeplinker-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "77a86695abe30412a4a6b36345113e18",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 8532,
            "upload_time": "2024-04-16T06:41:04",
            "upload_time_iso_8601": "2024-04-16T06:41:04.935664Z",
            "url": "https://files.pythonhosted.org/packages/e0/a0/2a32beecc674859c51bb424c469d9898a03f199d91340a5d3cb1d7d7dc14/streamlit_deeplinker-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bbaf0c47eba6de50ad4570a03f96529b0a386f91d44948ebe77298f952e291a4",
                "md5": "a18a754cac30752c16f05131d29491b5",
                "sha256": "aec5941033e376d3194169b38120bfd0b25534e7f7365dc6563c12a046119750"
            },
            "downloads": -1,
            "filename": "streamlit_deeplinker-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a18a754cac30752c16f05131d29491b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 7517,
            "upload_time": "2024-04-16T06:41:06",
            "upload_time_iso_8601": "2024-04-16T06:41:06.450937Z",
            "url": "https://files.pythonhosted.org/packages/bb/af/0c47eba6de50ad4570a03f96529b0a386f91d44948ebe77298f952e291a4/streamlit_deeplinker-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 06:41:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "streamlit-deeplinker"
}
        
Elapsed time: 0.24233s