streamlit-stacker


Namestreamlit-stacker JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/B4PT0R/streamlit_stacker
SummaryTool allowing to stack streamlit commands and resolve them in a controlable manner.
upload_time2024-02-04 10:29:17
maintainer
docs_urlNone
authorBaptiste Ferrand
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# streamlit_stacker

streamlit_stacker is a python package implementing a main st_stacker class.
This class can be used with similar syntax as the streamlit module but the attribute calls will be stacked in a list (the stack) instead of being resolved. A simple call to the refresh() method will deal with rendering (=actually execute the corresponding streamlit commands of) the whole stack on demand.

Populating a stack with attribute calls, context mangers and callbacks thus becomes similar to setting up a gui layout in an object oriented manner.

On top of being added to the stack, all st_stacker attribute calls will return one or several st_output objects. These are meant to be placeholder objects anticipating the reception of actual outputs returned by streamlit attribute calls when they will get executed. 

The .value property will get actualized in real time as soon as the corresponding streamlit widgets have a non-empty state.

This module is very useful to implement stateful and/or dynamic execution of streamlit commands in an interactive web interface.

It is meant to support all streamlit commands and syntaxes allowed by the streamlit module. If not, feel free to report an issue, we'll work on it :).

## Installation

```bash
$ pip install streamlit-stacker
```

## Usage

```python
import streamlit as st
from streamlit_stacker import st_stacker

#shortcut
state=st.session_state

#define the stacker in state
if not 'stacker' in state:
    state.stacker=st_stacker()
stk=state.stacker

#resets all commands in the stacker to a non-rendered state, so that the next call to refresh will render them again
stk.reset()

if not 'test' in state:
    #stack a chat message and a button in a container, won't be rendered immediately
    state.c=stk.container()
    with state.c:
        with stk.chat_message(name='user'):
            stk.write("Hello!")
            
    #callback to add a new message when the button is clicked
    def on_click():
        with state.c:
            with stk.chat_message(name='user'):
                stk.write("Hello again!")

    stk.button("click me!",on_click=on_click)
    state.test=True

#render the stack: the chat message and the button will appear on screen on every rerun, even though the corresponding commands have been called only once at first run
#every click on the button will add another chat message to the container
stk.refresh()
```

## License

This project is licensed. Please see the LICENSE file for more details.

## Contributions

Contributions are welcome. Please open an issue or a pull request to suggest changes or additions.

## Contact

For any questions or support requests, please contact Baptiste Ferrand at the following address: bferrand.maths@gmail.com.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/B4PT0R/streamlit_stacker",
    "name": "streamlit-stacker",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Baptiste Ferrand",
    "author_email": "bferrand.maths@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/dd/30/58690736beab3e7fd3a913ff92be3a1f82460194aaac5437bea1f85cd6c3/streamlit_stacker-0.0.6.tar.gz",
    "platform": null,
    "description": "\n# streamlit_stacker\n\nstreamlit_stacker is a python package implementing a main st_stacker class.\nThis class can be used with similar syntax as the streamlit module but the attribute calls will be stacked in a list (the stack) instead of being resolved. A simple call to the refresh() method will deal with rendering (=actually execute the corresponding streamlit commands of) the whole stack on demand.\n\nPopulating a stack with attribute calls, context mangers and callbacks thus becomes similar to setting up a gui layout in an object oriented manner.\n\nOn top of being added to the stack, all st_stacker attribute calls will return one or several st_output objects. These are meant to be placeholder objects anticipating the reception of actual outputs returned by streamlit attribute calls when they will get executed. \n\nThe .value property will get actualized in real time as soon as the corresponding streamlit widgets have a non-empty state.\n\nThis module is very useful to implement stateful and/or dynamic execution of streamlit commands in an interactive web interface.\n\nIt is meant to support all streamlit commands and syntaxes allowed by the streamlit module. If not, feel free to report an issue, we'll work on it :).\n\n## Installation\n\n```bash\n$ pip install streamlit-stacker\n```\n\n## Usage\n\n```python\nimport streamlit as st\nfrom streamlit_stacker import st_stacker\n\n#shortcut\nstate=st.session_state\n\n#define the stacker in state\nif not 'stacker' in state:\n    state.stacker=st_stacker()\nstk=state.stacker\n\n#resets all commands in the stacker to a non-rendered state, so that the next call to refresh will render them again\nstk.reset()\n\nif not 'test' in state:\n    #stack a chat message and a button in a container, won't be rendered immediately\n    state.c=stk.container()\n    with state.c:\n        with stk.chat_message(name='user'):\n            stk.write(\"Hello!\")\n            \n    #callback to add a new message when the button is clicked\n    def on_click():\n        with state.c:\n            with stk.chat_message(name='user'):\n                stk.write(\"Hello again!\")\n\n    stk.button(\"click me!\",on_click=on_click)\n    state.test=True\n\n#render the stack: the chat message and the button will appear on screen on every rerun, even though the corresponding commands have been called only once at first run\n#every click on the button will add another chat message to the container\nstk.refresh()\n```\n\n## License\n\nThis project is licensed. Please see the LICENSE file for more details.\n\n## Contributions\n\nContributions are welcome. Please open an issue or a pull request to suggest changes or additions.\n\n## Contact\n\nFor any questions or support requests, please contact Baptiste Ferrand at the following address: bferrand.maths@gmail.com.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Tool allowing to stack streamlit commands and resolve them in a controlable manner.",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/B4PT0R/streamlit_stacker"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae4d02b819aa4ab03f89be8b3b9bd38d1d23c2e673e9bd7dfa3b66f5898eda3e",
                "md5": "16cab77e311bb0c7d65c1d258fa3f348",
                "sha256": "d2d075b911ae647719b1fb4beecb9bded5fd56aaa3c2527c97a59700591bf5e9"
            },
            "downloads": -1,
            "filename": "streamlit_stacker-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "16cab77e311bb0c7d65c1d258fa3f348",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10148,
            "upload_time": "2024-02-04T10:29:15",
            "upload_time_iso_8601": "2024-02-04T10:29:15.899986Z",
            "url": "https://files.pythonhosted.org/packages/ae/4d/02b819aa4ab03f89be8b3b9bd38d1d23c2e673e9bd7dfa3b66f5898eda3e/streamlit_stacker-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd3058690736beab3e7fd3a913ff92be3a1f82460194aaac5437bea1f85cd6c3",
                "md5": "98c6b0b720144cc4057d116aae03cb33",
                "sha256": "436b39efff9de180cd342569985065abcc9ac6b0190d327f75c2f51c832de107"
            },
            "downloads": -1,
            "filename": "streamlit_stacker-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "98c6b0b720144cc4057d116aae03cb33",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10133,
            "upload_time": "2024-02-04T10:29:17",
            "upload_time_iso_8601": "2024-02-04T10:29:17.991061Z",
            "url": "https://files.pythonhosted.org/packages/dd/30/58690736beab3e7fd3a913ff92be3a1f82460194aaac5437bea1f85cd6c3/streamlit_stacker-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-04 10:29:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "B4PT0R",
    "github_project": "streamlit_stacker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "streamlit-stacker"
}
        
Elapsed time: 0.17464s