Name | streamlit-infinite-pages JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | Streamlit wrapper to add simple support for an arbitrary number of pages. |
upload_time | 2024-08-12 04:16:27 |
maintainer | None |
docs_url | None |
author | Hart Traveller |
requires_python | <4.0,>=3.10 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# streamlit-infinite-pages
Streamlit wrapper to make creating multi page apps easier.
## Install
```sh
pip install streamlit-infinite-pages
```
## Features
- [x] Simpler multi-page apps
- [x] Control traceback
- Fix security issue with base streamlit that leaks code/traceback into app
- [x] Customizable authentication flow
- [x] Per page authorization/access control
- [ ] Add simple branding/metadata integration
- [ ] Keyboard shortcuts
- [ ] Custom CSS / JS
- [ ] Add various stateful elements
## Tutorial
### One simple app
```python
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
```python
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.
```python
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.
```python
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.
```python
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.
```python
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")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "streamlit-infinite-pages",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Hart Traveller",
"author_email": "ruling_fiction.0b@icloud.com",
"download_url": "https://files.pythonhosted.org/packages/d4/b9/739c5f436915dc8f477899e73392f4a4d84683b17ee76cf55700cf60b710/streamlit_infinite_pages-0.1.1.tar.gz",
"platform": null,
"description": "# streamlit-infinite-pages\n\nStreamlit wrapper to make creating multi page apps easier.\n\n## Install\n\n```sh\npip install streamlit-infinite-pages\n```\n\n## Features\n\n- [x] Simpler multi-page apps\n- [x] Control traceback\n - Fix security issue with base streamlit that leaks code/traceback into app\n- [x] Customizable authentication flow\n- [x] Per page authorization/access control\n- [ ] Add simple branding/metadata integration\n- [ ] Keyboard shortcuts\n- [ ] Custom CSS / JS\n- [ ] Add various stateful elements\n\n\n## Tutorial\n\n### One simple app\n\n```python\nimport streamlit as st\nfrom sip import App, Page\n\ndef home_page() -> None:\n st.markdown(\"# Home\")\n\n\napp = App(\n name=\"Demo App\",\n icon=\"\ud83d\ude80\",\n)\n\napp.add(Page(name=\"Home\", main=home_page))\n\n# `index` is the default page\napp.run(index=\"Home\")\n```\n\n### Multi page app\n\n```python\nimport streamlit as st\nfrom sip import App, Page\n\ndef home_page() -> None:\n st.markdown(\"# Home\")\n\ndef other_page() -> None:\n st.markdown(\"# Other page\")\n\napp = App(\n name=\"Demo App\",\n icon=\"\ud83d\ude80\",\n)\n\napp.add(Page(name=\"Home\", main=home_page))\n\napp.add(Page(name=\"Other\", main=other_page))\n\n# alternatively, you can add pages as a list\n# app.add(\n# [\n# Page(name=\"Home\", main=home_page),\n# Page(name=\"Other\", main=other_page),\n# ],\n# )\n\napp.run(index=\"Home\")\n```\n\n### Control output traceback\n\nThis app will show the default traceback.\n\n```python\nimport streamlit as st\nfrom sip import App, Page\n\ndef zero_division_error() -> None:\n st.write(1 / 0)\n\napp = App(\n name=\"Demo App\",\n icon=\"\ud83d\ude80\",\n)\n\napp.add(Page(name=\"Error\", main=zero_division_error))\n\napp.run(index=\"Error\")\n```\n\nAnd this one will hide it. You can substitute whatever handler logic you want in here.\n\n```python\nimport streamlit as st\nfrom sip import App, Page\n\ndef zero_division_error() -> None:\n st.write(1 / 0)\n\ndef hidden_traceback(e: Exception) -> None:\n st.toast(\":red[Error]\")\n\napp = App(\n name=\"Demo App\",\n icon=\"\ud83d\ude80\",\n traceback_handler=hidden_traceback,\n)\n\napp.add(Page(name=\"Error\", main=zero_division_error))\n\napp.run(index=\"Error\")\n```\n\n\n\n### Add authentication flow\n\nYou 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.\n\n```python\nimport streamlit as st\nfrom sip import App, Page\n\ndef home_page() -> None:\n st.markdown(\"# Home\")\n\n# should return true if authentication succeeded, false if failed\n# otherwise if no input submitted none\ndef authentication_handler() -> bool | None:\n super_secret_password = \"qwerty\"\n password_input = st.text_input(label=\"Enter password:\", type=\"password\")\n if password_input:\n return password_input == super_secret_password\n else:\n return None\n\napp = App(\n name=\"Demo App\",\n icon=\"\ud83d\ude80\",\n auth_handler=authentication_handler,\n)\n\napp.add(Page(name=\"Home\", main=home_page))\n\napp.run(index=\"Home\")\n```\n\n### Per page authorization\n\nOf 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.\n\n```python\nimport streamlit as st\nfrom sip import App, Page\n\nusers = {\n \"alice\": {\n \"password\": \"ilikebob\",\n \"access\": \"basic\",\n },\n \"bob\": {\n \"password\": \"bobrocks\",\n \"access\": \"admin\",\n },\n}\n\ndef home_page() -> None:\n st.markdown(\"# Home\")\n\ndef admin_only_page() -> None:\n st.markdown(\"This page is only accessible to admins.\")\n\ndef admin_only_check() -> bool:\n return st.session_state[\"access\"] == \"admin\"\n\n# should return true if authentication succeeded, false if failed\n# otherwise if no input submitted none\ndef authentication_handler() -> bool | None:\n username_input = st.text_input(label=\"Enter username:\")\n password_input = st.text_input(label=\"Enter password:\", type=\"password\")\n if username_input and password_input:\n if not (username_input in users.keys()):\n return False\n else:\n if password_input == users[username_input][\"password\"]:\n st.session_state[\"user\"] = username_input\n st.session_state[\"access\"] = users[username_input][\"access\"]\n return True\n else:\n return False\n else:\n return None\n\n\napp = App(\n name=\"Demo App\",\n icon=\"\ud83d\ude80\",\n auth_handler=authentication_handler,\n initial_session_state={\"access\": None},\n)\n\napp.add(\n Page(name=\"Home\", main=home_page),\n)\n\napp.add(\n Page(\n name=\"only for admins\",\n main=admin_only_page,\n accessible=admin_only_check,\n )\n)\n\napp.run(index=\"Home\")\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Streamlit wrapper to add simple support for an arbitrary number of pages.",
"version": "0.1.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3c8c973e084fe6cc36e0b3184819cb878ebc4deb1f2ddfba9137dfc31b257f17",
"md5": "2633a1279bce3c4aa8a20b820e96ece0",
"sha256": "1945cd30e9e7d235f95efc17b98cf6af299f8b004da28f474255f61f1416768a"
},
"downloads": -1,
"filename": "streamlit_infinite_pages-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2633a1279bce3c4aa8a20b820e96ece0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 5441,
"upload_time": "2024-08-12T04:16:26",
"upload_time_iso_8601": "2024-08-12T04:16:26.346731Z",
"url": "https://files.pythonhosted.org/packages/3c/8c/973e084fe6cc36e0b3184819cb878ebc4deb1f2ddfba9137dfc31b257f17/streamlit_infinite_pages-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d4b9739c5f436915dc8f477899e73392f4a4d84683b17ee76cf55700cf60b710",
"md5": "a3186ea93c87133eefc7869894af0b10",
"sha256": "ccb9f230b4e37c7f49f6ea0f58c9f490b3556b8c072f4caaa8b2fc10986c71d2"
},
"downloads": -1,
"filename": "streamlit_infinite_pages-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "a3186ea93c87133eefc7869894af0b10",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 4549,
"upload_time": "2024-08-12T04:16:27",
"upload_time_iso_8601": "2024-08-12T04:16:27.738264Z",
"url": "https://files.pythonhosted.org/packages/d4/b9/739c5f436915dc8f477899e73392f4a4d84683b17ee76cf55700cf60b710/streamlit_infinite_pages-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-12 04:16:27",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "streamlit-infinite-pages"
}