An easy to use actor model framework in Python
pip install sparkSpark
Spark is an async-first actor framework for Python. The core API is small:
start a Syndicate, create actors, and send messages with tell(message, target) or ask(message, target).
Workflow routing lives in the explicit spark.workflow package. Distributed
features such as TCP routes, WebSocket routes, relay traversal, federation, and
persistence are opt-in.
Install
pip install spark
pip install "spark[cbor2]" # structured remote payloads
pip install "spark[websocket,cbor2]" # websocket and NAT relay examples
For local development:
uv venv -p 3.13
uv pip install -e ".[dev,test,websocket,cbor2]"
uv run pytest
Quick Start
from spark import Actor, Syndicate
from spark.core.message import Message
class Echo(Actor):
async def process(self, message: Message) -> str:
return f"echo:{message.content}"
async with Syndicate("app") as system:
echo = await system.create_actor(Echo)
print(await system.ask("hello", echo, timeout=1.0))
tell(message, target) is fire-and-forget. ask(message, target) waits for
the first reply or raises ActorTimeout.
await system.tell("event", echo)
reply = await system.ask("request", echo, timeout=5.0)
Inside an actor, omitting target sends to the owning syndicate inbox today;
that shape is reserved for future broadcast/parent behavior.
Core Capabilities
- Actor lifecycle through explicit
Syndicateinstances. - Parent/child actors, monitoring, linking, and restart/resume/escalate supervision.
- Bounded mailboxes, TTL/deadline delivery, dead letters, late replies, runtime events, and diagnostics snapshots.
- Stateless thread/process execution with
ActorSpec. Troupeactor pools for parallel local work.- Durable actors and durable timers through
SQLiteJournal. - TCP remote routes with shared-secret HMAC handshake and frame integrity.
- WebSocket direct routes and authenticated WebSocket relay registration for outbound-only NAT traversal.
- Authenticated federation membership and remote actor placement.
Workflow Layer
Workflow support is intentionally separate from the actor root API: