Skip to main content

SSE adapter for Muscles streaming events

Project description

Muscles SSE

Server-Sent Events adapter for Muscles streaming use cases.

This package should provide progress, logs, notifications, and AI output streams over SSE while keeping the underlying workflow in the Muscles application model.

Related Repositories

Concept Guardrails

  • SSE streams must be backed by Muscles actions/events/jobs, not ad hoc handlers.
  • The adapter must preserve shared rules/security and request context.
  • Stream events must have typed names and payload schemas.
  • SSE should be the simple default for one-way streaming before WebSocket is introduced.
  • The package must be usable from ASGI without forcing unrelated runtime choices.

Current Stage (Issue #1)

Implemented SSE transport projection over Muscles action execution:

  • action dispatch path: dispatcher.execute(action, payload, transport="sse");
  • application facade: SseAdapter.from_application(app) backed by core ActionDispatcher;
  • stream normalization delegates to core stream_events() / StreamResult;
  • typed events: progress, log, result, error;
  • wire formatting: id, event, retry, data;
  • SseResponse with SSE headers and status;
  • configurable interval heartbeat with bounded backpressure;
  • safe source close on stream completion/disconnect;
  • structured core action error mapping: not found, validation, permission, execution.

This keeps SSE as a thin delivery layer. Business logic stays in Muscles actions.

Interval heartbeat

SSE serializes core StreamEvent items from StreamResult. Business events come from muscles.core; this package owns the SSE wire format and transport heartbeat, backpressure, and disconnect behavior.

adapter = SseAdapter(
    dispatcher,
    heartbeat_event="heartbeat",
    heartbeat_interval_seconds=15,
)

When the action stream is quiet longer than the configured interval, the transport emits a heartbeat event:

event: heartbeat
data: {"ok": true}

User events keep their existing SSE format. Closing the response stream stops the heartbeat worker and closes the underlying source when it supports close(). Backpressure is preserved with a bounded one-item queue. Long- blocking sources should implement a cooperative close() that unblocks the active next() call.

Run tests

python -m pytest -q

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

muscles_sse-1.0.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

muscles_sse-1.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file muscles_sse-1.0.2.tar.gz.

File metadata

  • Download URL: muscles_sse-1.0.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for muscles_sse-1.0.2.tar.gz
Algorithm Hash digest
SHA256 fba5078ead80aca89826bc9c0093a53cccb76b0aaf80d6220b1e1aead7eeb359
MD5 d46b4849571a241d93239c99d1fd025e
BLAKE2b-256 0cb4d53c1f74e8fa43f122cbd321eb08663d5862d8b0d139c600845754fa51e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_sse-1.0.2.tar.gz:

Publisher: release.yml on butkoden/muscles-sse

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

File details

Details for the file muscles_sse-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: muscles_sse-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for muscles_sse-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ce7771a22d8f30a7eedb45245514853c3d01e26da8f3635186cb6a64c2d5c669
MD5 e276631cad8cb468c5ed2acb78172df4
BLAKE2b-256 47db78938a225079e40dfbe38d0f8d6df22897c74a0be3589a8086ce2a951e51

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_sse-1.0.2-py3-none-any.whl:

Publisher: release.yml on butkoden/muscles-sse

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