Streamlit-flavored components with an event-driven (no-rerun) runtime.
The app function runs once to build a persistent component tree. Later interactions run only the handlers registered on signals, and the browser patches the DOM in place. There is no page reload and no script re-run.
- Performant by design. The app function runs once. An interaction executes only the handlers attached to it, then patches the DOM. The script never re-runs.
- Reactive, polished event-driven syntax.
sc.bindandsc.bbindbuild derived and two-way values,on_changeand component signals attach handlers, and a forced notification (set(value, notify=True)) refreshes output when the value itself did not change. - Desktop windows.
sc.run(..., show_window=True)serves the app and opens it in a nativepyapp-windowwindow, sized in CSS pixels. - Custom components included. Folder trees,
PathInputBrowse, a PDF viewer, a live log panel, animated toasts, and the rest of the library ship with the package. dunder_literal.PageConfig(dunder_literal=True)keeps names such as__init__and__name__from turning into bold text.- Fewer dependencies. The core runs without Streamlit, pandas,
NumPy, SciPy, pyarrow, or Altair. Altair is needed only if you use
AltairChart.
pip install streamlit-canaryPython 3.11 or newer is required.
import streamlit_canary as sc
class State(sc.State):
count = sc.Property(0)
state = State()
def app():
sc.PageTitle('Click Counter')
with sc.Row('center'):
with sc.Text('Click count: 0') as txt:
@state.count.on_change.partial(sc._self)
def _(cnt):
txt.text.set('Click count: {}'.format(cnt.get()))
with sc.Button('Increase counter', type='primary') as btn:
@btn.on_click
def _():
state['count'] += 1
if __name__ == '__main__':
sc.run(app, port=2201)Save it as app.py, run python app.py, and open
http://localhost:2201. Clicking the button updates the text in place;
app() is not called again.
sc.run(
app,
show_window=True,
window_size=(980, 760),
window_title='My App',
)window_size is the page viewport in CSS pixels, so the layout receives
exactly the size requested, independent of the display scale factor.
'maximized' and 'fullscreen' are also accepted.
examples/click_counter.py— the minimal event-driven app.examples/bind_multi_source.py— single-source and multi-sourcesc.bind, plus batched updates withsc.pending_updates().examples/tree_select_multicross.py— folder trees with single, multiple, and cross-folder selection.
Run any of them directly:
python examples/click_counter.pyThe full user manual lives in
docs/user-manual/src/index.md.
To preview it locally:
cd docs/user-manual
mdbook serve