Meet Casty
Typed, clustered actor framework for Python
Casty is a typed, clustered actor framework for Python built on asyncio. Pure Python, zero dependencies. Actors communicate exclusively through immutable messages, from a single process to a distributed cluster.
- Behaviors are values, not classes. No
Actorbase class. Behaviors are frozen dataclasses produced by factory functions, composed like any other value. - State lives in closures. State transitions happen by returning a new behavior that closes over the new state. No mutable fields, no
self.balance = .... - Immutability by default. All messages, behaviors, events, and configurations are frozen dataclasses.
- Zero external dependencies. Pure Python, stdlib only.
- Type-safe end-to-end.
ActorRef[M],Behavior[M], and PEP 695 type aliases catch message mismatches at development time. - Cluster-ready. Distribute actors across nodes with gossip-based membership, phi accrual failure detection, and automatic shard rebalancing.
Quick Example¶
@dataclass(frozen=True)
class Greet:
name: str
def greeter() -> Behavior[Greet]:
async def receive(ctx: ActorContext[Greet], msg: Greet) -> Behavior[Greet]:
print(f"Hello, {msg.name}!")
return Behaviors.same()
return Behaviors.receive(receive)
async def main() -> None:
async with ActorSystem() as system:
ref = system.spawn(greeter(), "greeter")
ref.tell(Greet("Alice"))
await asyncio.sleep(0.1)
asyncio.run(main())
# Hello, Alice!
Next Steps¶
- Getting Started — Installation, first actor, core concepts
- Concepts — Actors, behaviors, state, supervision, and more
- Persistence — Event sourcing for durable actor state
- Clustering — Distribute actors across multiple nodes
- Configuration — TOML-based configuration for all parameters
- API Reference — Full autodoc of all public types