Skip to main content

Spark

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 Syndicate instances.
  • 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.
  • Troupe actor 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:

from spark import Syndicate
from spark.core.message import Message
from spark.workflow import Node, Workflow


class Normalize(Node):
    def process(self, message: Message) -> str:
        return str(message.content).strip().lower()


first = Normalize()
workflow = Workflow(start=first)

async with Syndicate("workflow-app") as system:
    print(await workflow.run("  Spark  ", system=system))

Workflow starts its nodes in an explicit Syndicate, validates edges, initializes workflow state, and never uses the global actor system. Workflow state is not a checkpoint/replay engine; use persistent actors when state must survive restart.

Networking

Direct TCP on a trusted route:

left = Syndicate("left", remote=True, transport_secret="shared")
right = Syndicate("right", remote=True, transport_secret="shared")

WebSocket relay for two NATed networks:

export SPARK_RELAY_SECRET="change-me"
uv run --extra websocket --extra cbor2 spark-ws-relay \
  --host 0.0.0.0 --port 8765 --auth-secret-env SPARK_RELAY_SECRET

Both actor systems then call:

await system.connect_relay("wss://relay.example.net/spark", secret=relay_secret)

Relay authentication prevents unauthenticated system registration. It does not encrypt traffic by itself; use wss:// or a TLS-terminating reverse proxy outside local demos.

Examples

Phase 9 adds runnable examples by feature area:

python examples/basic_actor_echo.py --message hello
python examples/workflow_router.py --score 95
python examples/tcp_two_hosts.py local --codec trusted-pickle
python examples/nat_relay_service.py local --codec trusted-pickle --secret shared
python examples/federation_placement.py local --codec trusted-pickle

See docs/examples.md for the complete index and --help output for each script.

Documentation

  • docs/actor_overview.md: API walkthrough.
  • docs/actor_semantics.md: delivery, ordering, failure, and shutdown semantics.
  • docs/security.md: transport, codec, relay, federation, and artifact trust.
  • docs/networking.md: TCP, WebSocket, relay/NAT, and federation recipes.
  • docs/workflow.md: workflow layer guide.
  • docs/features.md: stable, optional, experimental, and removed surfaces.
  • docs/spark_ug.md: broader user guide.

Development Checks

uv run pytest
uv run ruff check spark tests examples
uv run mypy spark
uv run black spark tests examples

Metadata

Release files for Spark 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Spark 0.4.1
File Size Uploaded
spark-0.4.1.tar.gz 131.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Spark 0.4.1
File Interpreter ABI Platform
spark-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 296.0 kB

Release files / spark-0.4.1.tar.gz

Download URL spark-0.4.1.tar.gz
Size 131.4 kB
Tags Source
SHA-256 checksum
How to use checksums
adaf63da20392e9ff0aa5ac1b425a930ad1496670dd6328ae869d99c571a1831
BLAKE2b-256 checksum
How to use checksums
f1598eedb71a9a05c6f5ab3f1b20600d5e52f601a06290121de6b3c4743aa37d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.13 Linux/5.15.0-164-generic

Release files / spark-0.4.1-py3-none-any.whl

Download URL spark-0.4.1-py3-none-any.whl
Size 164.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74c17e00e9a8ffb70a21efca7b14ef7882bfb94347f737f43167406c0644b507
BLAKE2b-256 checksum
How to use checksums
29c212137220bc97b7876a2fc2835c948881419a929fe3835dcabe35cc7289f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.13 Linux/5.15.0-164-generic

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page