Skip to main content

A Streamlit extension for the Tiferet Framework

Project description

tiferet-streamlit

A Streamlit extension for the Tiferet Framework — build multi-page Streamlit applications with Domain-Driven Design.

Installation

pip install tiferet-streamlit

Quick Start

import streamlit as st
from tiferet_streamlit import StreamlitApp, ViewContext

class HomeView(ViewContext):
    def init_state(self):
        self.session.set('count', 0)

    def render(self):
        count = self.session.get('count')
        st.title('Home')
        st.write(f'Count: {count}')
        if st.button('Increment'):
            self.session.set('count', count + 1)
            st.rerun()

app = StreamlitApp()
app.load_app_service()
app.run('my_interface', pages={'/': HomeView})

Core Concepts

ViewContext

The code-behind for a Streamlit page. Manages state via SessionCacheContext, dispatches Tiferet features via AppInterfaceContext, and defines UI through render().

  • init_state() — Called once on first construction. Override to set initial state.
  • dispatch(feature_id, headers=None, **data) — Execute a Tiferet feature.
  • render() — Override to define Streamlit widgets.
  • __call__() — Makes the view callable for st.Page composition.

ViewComponent

A lightweight, prop-driven sub-component with parent ViewContext access.

from tiferet_streamlit import ViewComponent

class Counter(ViewComponent):
    def render(self, label='Count', start=0):
        count = self.ctx.session.get('count') or start
        st.write(f'{label}: {count}')

SessionCacheContext

Cache backed by st.session_state with namespace isolation for multi-page apps.

from tiferet_streamlit import SessionCacheContext

cache = SessionCacheContext(namespace='my_view')
cache.set('key', 'value')
cache.get('key')  # 'value'

Multi-Page Applications

Use PageContext to register multiple views with routes:

app.run('my_interface', pages={
    '/': HomeView,
    '/about': AboutView,
    '/settings': SettingsView,
})

Config-Driven Pages

Define pages as Page domain objects for YAML-driven configuration:

from tiferet_streamlit import Page

pages = [
    Page(route='/', title='Home', icon='🏠',
         view_module_path='app.views.home', view_class_name='HomeView'),
    Page(route='/about', title='About', icon='ℹ️',
         view_module_path='app.views.about', view_class_name='AboutView'),
]

app.run('my_interface', page_configs=pages)

Feature Dispatch

Views dispatch Tiferet features for backend logic:

class CalcView(ViewContext):
    def render(self):
        a = st.number_input('a')
        b = st.number_input('b')
        if st.button('Add'):
            result = self.dispatch('calc.add', a=a, b=b)
            st.write(f'Result: {result}')

API Reference

Class Module Description
Page domain.view Page configuration domain object
ViewService interfaces.view Abstract service for page management
SessionCacheContext contexts.session Session-state-backed cache with namespacing
ViewContext contexts.view Page code-behind with lifecycle management
ViewComponent contexts.view Prop-driven sub-component
PageContext contexts.page Multi-page navigation manager
StreamlitBuilder builders.main Application entry point (also aliased as StreamlitApp)

Development

# Clone and set up
git clone https://github.com/greatstrength/tiferet-streamlit.git
cd tiferet-streamlit
python -m venv .venv
source .venv/bin/activate
pip install -e .[test]

# Run tests
pytest --verbose

License

MIT

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

tiferet_streamlit-0.1.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tiferet_streamlit-0.1.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file tiferet_streamlit-0.1.0.tar.gz.

File metadata

  • Download URL: tiferet_streamlit-0.1.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tiferet_streamlit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f0ed4b4a8ae6179653eb0d4a554efce9d61189761dce8f38b89895bd67e38af1
MD5 0724ce8fe3de1f84615f9abbab3c0a9b
BLAKE2b-256 348c084871cae3d2412d4a35364476acc1240824e0eaa3433707335f49bfdbc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiferet_streamlit-0.1.0.tar.gz:

Publisher: python-publish.yml on greatstrength/tiferet-streamlit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiferet_streamlit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tiferet_streamlit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20bd8bee4b54de50e3164f7f6e2ed424026e89d3da5d2498607fbe828fcede1a
MD5 b2ba08ab3eb43f3441038217f4999baf
BLAKE2b-256 4707687d0fb3b92d10f2eb6da56238229f99caa8f258d235a767119f10b167a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiferet_streamlit-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on greatstrength/tiferet-streamlit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page