Skip to main content

Tool allowing to stack streamlit commands and resolve them in a controlable manner.

Project description

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

$ pip install streamlit-stacker

Usage

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.

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_stacker-0.0.4.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

streamlit_stacker-0.0.4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_stacker-0.0.4.tar.gz.

File metadata

  • Download URL: streamlit_stacker-0.0.4.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for streamlit_stacker-0.0.4.tar.gz
Algorithm Hash digest
SHA256 6c534abbbf0964de6321536a265617e9eba2a94290a72ebbe3aa38cebdf88318
MD5 8e916ff00eb1501e53c7f8260db41f69
BLAKE2b-256 0bc48db6758970359792edd0c3e188f1c8944d3a84a9c5053b55c4e3c9068b50

See more details on using hashes here.

File details

Details for the file streamlit_stacker-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_stacker-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ed93fc929e78996691f198c725e7b3844500dc1aebc90b3e23552ce867a0ac5e
MD5 2de9f70e1342c8a980f2b63ffc0bdb41
BLAKE2b-256 9a3f7d19dfa7c4fabd2c9c8d55ca09e73f86a93b680cf1fb620bd56ba6bf0d2f

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