Dash Event Callback
Server sent event based callbacks for Dash
Event Callback
Server-Sent Events (SSEs) are a server push technology that keeps an HTTP connection open, allowing servers to continuously stream updates to clients. They are typically used for sending messages, data streams, or real-time updates directly to the browser via the native JavaScript EventSource API.
NOTE: Dash/Flask are synchronus, which leads to SSE's blocking a whole worker for the durtion of the execution. Thats why this package has 60sec timeout integrated. If you want to use event callbacks extensively - you should consider using Flash.
fvent callbacks build on this principle by using generator functions that yield updates instead of returning once. This enables:
- Progressive UI updates (e.g., streaming partial results).
The API mirrors Dash’s callback design, but with two key differences:
- No explicit output needed – updates are applied with stream_props.
stream_propsbehaves like set_props, needs to be yield.
Stream Props
The stream_props function allows you to send UI updates on the fly and follows the set_props API by Dash, while enhancing it with batch updates which reduces network overhead and quicker UI updates. The function can be used as follows:
# Single updates
yield stream_props(component_id="cid", props={"children": "Hello Stream"})
yield stream_props("cid", {"children": "Hello Stream"})
# Batch updates
yield stream_props(batch=[
("cid", {"children": "Hello Stream"}),
("btn", {"disablesd": True}),
])
yield stream_props([
("cid", {"children": "Hello Stream"}),
("btn", {"disablesd": True}),
])
Basic Event Callback
This example (from Dash’s background callback docs) shows how a background callback is no longer necessary—eliminating the need for extra services like Celery + Redis.
# data.py
import pandas as pd
import time
def get_data(chunk_size: int):
df: pd.DataFrame = data.gapminder()
total_rows = df.shape[0]
while total_rows > 0:
time.sleep(2)
end = len(df) - total_rows + chunk_size
total_rows -= chunk_size
update_data = df[:end].to_dict("records")
df.drop(df.index[:end], inplace=True)
yield update_data, df.columns
A more realistic use case would be streaming query results with SQLAlchemy async:
# data.py
from sqlalchemy import Connection
def get_data(connection: Connection):
result = connection.execute(select(users_table))
for partition in partition_results(result, 100):
print("list of rows: %s" % partition)
yield partition
# Helper function to partition results
def partition_results(result, size):
partition = []
for row in result:
partition.append(row)
if len(partition) == size:
yield partition
partition = []
if partition:
yield partition
Hooking it into your app with event_callback:
# app.py
from flash import Input, event_callback, stream_props
@event_callback(Input("start-stream-button", "n_clicks"))
def update_table(_):
yield stream_props([
("start-stream-button", {"loading": True}),
("cancel-stream-button", {"display": "flex"})
])
progress = 0
chunk_size = 500
for data_chunk, colnames in get_data(chunk_size):
if progress == 0:
columnDefs = [{"field": col} for col in colnames]
update = {"rowData": data_chunk, "columnDefs": columnDefs}
else:
update = {"rowTransaction": {"add": data_chunk}}
yield stream_props("dash-ag-grid", update)
if len(data_chunk) == chunk_size:
yield NotificationsContainer.send_notification(
title="Starting stream!",
message="Notifications in Dash, Awesome!",
color="lime",
)
progress += 1
yield stream_props("start-stream-button", {"loading": False, "children": "Reload"})
yield stream_props("reset-strea-button", {"display": "none"})
Metadata
Release files for dash-event-callback 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dash_event_callback-1.2.0.tar.gz | 15.8 kB | Without provenance | Details for dash_event_callback-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dash_event_callback-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for dash_event_callback-1.2.0-py3-none-any.whl |
Total release size: 33.6 kB
Release files / dash_event_callback-1.2.0.tar.gz
| Download URL | dash_event_callback-1.2.0.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d843928a6409ff6483c1efa6a399fb423b38d722f54ee57e6fd3d48fd32ad8db
|
|
BLAKE2b-256 checksum How to use checksums |
accf61e161960a907dd4fcfa3cd52cbef2fa0a5288dd4aa7c3953a4f4385981e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.12.7 Darwin/24.6.0
|
Release files / dash_event_callback-1.2.0-py3-none-any.whl
| Download URL | dash_event_callback-1.2.0-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
852f052d1f31bbdaacdf9a9317b11e876279c6c5a80d05cd18164baec2f79c71
|
|
BLAKE2b-256 checksum How to use checksums |
319a30088400e472685977b0aa1aa38e2c96cc027409bb7758b1509a086688ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.12.7 Darwin/24.6.0
|
Security for dash-event-callback 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.