Skip to content

Meet Casty

Casty

Typed, clustered actor framework for Python

PyPI Python Tests License


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 Actor base 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