Typed, clustered actor framework for Python. Pure asyncio, zero dependencies.
Project description
Typed, clustered actor framework for Python
Documentation · Getting Started · PyPI
Casty is a typed, clustered actor framework for Python built on asyncio. Instead of threads, locks, and shared mutable state, you model your system as independent actors that communicate exclusively through immutable messages, from a single process to a distributed cluster.
Quick Start
pip install casty
import asyncio
from dataclasses import dataclass
from casty import ActorContext, ActorSystem, Behavior, Behaviors
@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"))
ref.tell(Greet("Bob"))
await asyncio.sleep(0.1)
asyncio.run(main())
# Hello, Alice!
# Hello, Bob!
Features
- Behaviors as values, not classes — No
Actorbase class. Behaviors are frozen dataclasses composed through factory functions. - State via closures — Actor state is captured in closures. State transitions happen by returning a new behavior with new closed-over values. No mutable fields, no
nonlocal. - Immutability by default — All messages, behaviors, events, and configurations are frozen dataclasses.
- Type-safe end-to-end —
ActorRef[M],Behavior[M], and PEP 695 type aliases ensure message type mismatches are caught at development time. - Zero external dependencies — Pure Python, stdlib only.
- Supervision — "Let it crash" philosophy with configurable restart strategies, inspired by Erlang/OTP.
- Event sourcing — Persist actor state as a sequence of events with automatic recovery on restart.
- Cluster sharding — Distribute actors across nodes with gossip-based membership, phi accrual failure detection, and automatic shard rebalancing.
- Shard replication — Passive replicas with automatic promotion on node failure.
- Cluster broadcast — Fan-out messages to all nodes with typesafe aggregated responses.
- Distributed data structures — Counter, Dict, Set, Queue, Lock, Semaphore, and Barrier built on sharded actors.
- TOML configuration — Optional
casty.tomlfor environment-specific tuning with per-actor overrides.
Documentation
Full documentation is available at gabfssilva.github.io/casty.
| Section | Description |
|---|---|
| Getting Started | Installation and first steps |
| Concepts | Actors, behaviors, state, request-reply, hierarchies, supervision, state machines |
| Persistence | Event sourcing with journals and snapshots |
| Clustering | Sharding, broadcast, replication, distributed data structures |
| Configuration | TOML-based configuration with per-actor overrides |
| API Reference | Complete API documentation |
Acknowledgments
Casty builds on the actor model (Hewitt, 1973), Erlang/OTP's supervision philosophy, Akka Typed's functional behavior API, and distributed systems research including phi accrual failure detection, gossip protocols, CRDTs, and vector clocks. See the full Acknowledgments page for details and references.
Contributing
git clone https://github.com/gabfssilva/casty
cd casty
uv sync
uv run pytest # run tests
uv run pyright src/casty/ # type checking (strict mode)
uv run ruff check src/ tests/ # lint
uv run ruff format src/ tests/ # format
License
MIT — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file casty-0.16.0.tar.gz.
File metadata
- Download URL: casty-0.16.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37b100844992a43ee36742962dca22b15c612d08dbded22a0a530d02a793c8cf
|
|
| MD5 |
c2956e3f439cc93999dd5ab9c8a5f536
|
|
| BLAKE2b-256 |
2afb3b9810eca90bfedf77ea75acbd02a215e5cf186fdda20bd45fc74711d88d
|
Provenance
The following attestation bundles were made for casty-0.16.0.tar.gz:
Publisher:
publish.yml on gabfssilva/casty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
casty-0.16.0.tar.gz -
Subject digest:
37b100844992a43ee36742962dca22b15c612d08dbded22a0a530d02a793c8cf - Sigstore transparency entry: 953411943
- Sigstore integration time:
-
Permalink:
gabfssilva/casty@09af9e4d4ae90fd5b51b4c0617ab5832d328113d -
Branch / Tag:
refs/tags/v0.16.0 - Owner: https://github.com/gabfssilva
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09af9e4d4ae90fd5b51b4c0617ab5832d328113d -
Trigger Event:
release
-
Statement type:
File details
Details for the file casty-0.16.0-py3-none-any.whl.
File metadata
- Download URL: casty-0.16.0-py3-none-any.whl
- Upload date:
- Size: 111.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb45bbcb2e6a65ce535a28d05606e14b6b5d226388b64d7e331acd41075b88af
|
|
| MD5 |
2b68bf834f63a1fce156e2c55b672a2f
|
|
| BLAKE2b-256 |
e56fae5c77ca81577e9632aea11ce95445321e21d8acd9cd71aaf3b58cf2636a
|
Provenance
The following attestation bundles were made for casty-0.16.0-py3-none-any.whl:
Publisher:
publish.yml on gabfssilva/casty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
casty-0.16.0-py3-none-any.whl -
Subject digest:
eb45bbcb2e6a65ce535a28d05606e14b6b5d226388b64d7e331acd41075b88af - Sigstore transparency entry: 953411944
- Sigstore integration time:
-
Permalink:
gabfssilva/casty@09af9e4d4ae90fd5b51b4c0617ab5832d328113d -
Branch / Tag:
refs/tags/v0.16.0 - Owner: https://github.com/gabfssilva
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09af9e4d4ae90fd5b51b4c0617ab5832d328113d -
Trigger Event:
release
-
Statement type: