realtime.signals

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

Chirpsignal()— the declare-once / bind-many live-value primitive.

A signal is a server-owned named value, declared once, that fans out over a single shared SSE connection to everytemplate binding that…

Chirpsignal()— the declare-once / bind-many live-value primitive.

A signal is a server-owned named value, declared once, that fans out over a single shared SSE connection to every template binding that listens for it. {{ signal('balance') }} in the topbar and {{ signal('balance') }}in a modal both swap together from one update on the wire — a cardinality plain OOB cannot express. Htmx 2 uses a named event; htmx 4 uses one targeted partial whose data-chirp-signalselector matches every sink.

This module is the framework substrate behind the public@app.signal/ @app.derived / app.emit surface and the signal() / signal_block() /signal_connect()template globals. It is intentionally a thin layer over existing transport:

  • The private signal update remains client-neutral until the SSE response boundary chooses the frozen htmx 2 or htmx 4 dialect.

  • ReactiveBusprovides the free-threaded (threading.Lock + per-subscriber asyncio.Queue + call_soon_threadsafe

    • bounded back-pressure) fan-out. Here the bus scope is the signal name.

    Free-threading (3.14t):SignalSpec / DerivedSpecare frozen/slots; the registry's mutable maps + value cache are guarded by a singlethreading.Lock (mirroring OOBRegistry). Cross-thread emits ride the bus'scall_soon_threadsafedelivery path, so a sync-mode producer can app.emit(...)safely.

realtime.signals

Name Type Default Description
type
qualified_name
element_type
description
source_file
line_number
is_autodoc
autodoc_element
_autodoc_template
_autodoc_url_path
_autodoc_page_type
title
doc_content_hash

Symbols on this page

validate_signal_name
function
def validate_signal_name(name: str) -> str

Return name if it is a legal signal name, else raiseValueError.

A signal name must be a non-empty string matching[A-Za-z0-9_.:-]+so it is safe as both an htmxsse-swap attribute value and an SSE event: field. Rejection happens at registration, not at emit.

Parameters

Name Type Default Description
name str
SignalSpec
class

Declaration of one signal — one producer, many bindings.

DerivedSpec
class

Declaration of a derived signal — recomputed from other signals.

A derived signal recomputes and re-emits whenever any of itsdeps changes.compute receives the current values of deps(positionally, in declaration order) and returns the derived value.

SignalRegistry
class

Free-thread-safe registry of signals + derived signals.

Holds the spec maps, a current-value cache (for SSR seeding and derived recompute), and aReactiveBusfor fan-out keyed by signal name. All mutable state is guarded by a singlethreading.Lock.

_rendered_marker
function
def _rendered_marker(name: str) -> str

Marker path stored in a ChangeEvent for signal name.

Parameters

Name Type Default Description
name str
_bus_scope
function
def _bus_scope(name: str, audience_key: str) -> str

Opaque ReactiveBus scope for a process-local signal fan-out.

Parameters

Name Type Default Description
name str
audience_key str
_dep_audience
function
def _dep_audience(spec: SignalSpec | None, derived: DerivedSpec | None) -> SignalAudience

Return the audience of a registered dependency.

Parameters

Name Type Default Description
spec SignalSpec | None
derived DerivedSpec | None
_values_equal
function
def _values_equal(a: Any, b: Any) -> bool

Whether two cached signal values are equal for emit dedup.

A purerendermaps equal values to equal payloads, so skipping the re-emit of an unchanged value never drops a real DOM change. ReturnsFalseon any comparison error (e.g. a value whose__eq__raises or is ambiguous), so the safe default is always "treat as changed → emit".

Parameters

Name Type Default Description
a Any
b Any

View source · /home/runner/work/chirp/chirp/site/../src/chirp/realtime/signals.py:1