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

Requires tiferet>=2.0.0b3 and streamlit>=1.30.0.

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()

StreamlitApp('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 StreamlitApp (or build_streamlit_app) to register multiple views with routes:

StreamlitApp('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, StreamlitApp

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'),
]

StreamlitApp('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

Export Module Description
build_streamlit_app blueprints.streamlit Primary entry point blueprint function
StreamlitApp blueprints Alias for build_streamlit_app
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

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.2.0.tar.gz (18.5 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.2.0-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tiferet_streamlit-0.2.0.tar.gz
  • Upload date:
  • Size: 18.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 dff7a46414cf80bf6e30d0c65b3defdc336e3ec893b38a2ded7539f294781f1f
MD5 b3bd12036171f28a5c6e95360272ccb9
BLAKE2b-256 a6718a487ab6ec4773c803ac34f48932dd14977f6dd9272d0da9a30e6eb65169

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiferet_streamlit-0.2.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.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tiferet_streamlit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c992d17df93c76da879f551a5b58d50a9d2259baed74bd52216ee045665a1e69
MD5 b8f6ec19a6ba67ad5767988eee4d8f8b
BLAKE2b-256 f8c662a7442af058b9d534656dc0d172caea8f98c1a36275e7cd4941b19c36b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiferet_streamlit-0.2.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