Skip to main content

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.

Metadata

Release files for streamlit-stacker 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-stacker 0.0.6
File Size Uploaded
streamlit_stacker-0.0.6.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-stacker 0.0.6
File Interpreter ABI Platform
streamlit_stacker-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 20.3 kB

Release files / streamlit_stacker-0.0.6.tar.gz

Download URL streamlit_stacker-0.0.6.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
436b39efff9de180cd342569985065abcc9ac6b0190d327f75c2f51c832de107
BLAKE2b-256 checksum
How to use checksums
dd3058690736beab3e7fd3a913ff92be3a1f82460194aaac5437bea1f85cd6c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / streamlit_stacker-0.0.6-py3-none-any.whl

Download URL streamlit_stacker-0.0.6-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2d075b911ae647719b1fb4beecb9bded5fd56aaa3c2527c97a59700591bf5e9
BLAKE2b-256 checksum
How to use checksums
ae4d02b819aa4ab03f89be8b3b9bd38d1d23c2e673e9bd7dfa3b66f5898eda3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page