Skip to main content

A minimalist, type-safe actor framework for Python 3.12+ inspired by Akka Typed

Project description

Casty

Minimalist, type-safe actor framework for Python 3.12+

PyPI Python Tests License

Documentation · Getting Started · PyPI


Casty is an actor framework inspired by Akka Typed that brings the behavior-driven, functional actor model to Python. Instead of threads, locks, and shared mutable state, you model your system as independent actors that communicate exclusively through messages.

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 Actor base 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-endActorRef[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.toml for 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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

casty-0.7.0.tar.gz (525.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

casty-0.7.0-py3-none-any.whl (88.1 kB view details)

Uploaded Python 3

File details

Details for the file casty-0.7.0.tar.gz.

File metadata

  • Download URL: casty-0.7.0.tar.gz
  • Upload date:
  • Size: 525.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for casty-0.7.0.tar.gz
Algorithm Hash digest
SHA256 651c448facb7e439f485924458057d4932b2f34d893860d4a9490a487eecd92a
MD5 c67d90ceac9970063944d9a220316ac2
BLAKE2b-256 3161cbb5f90e72fc9a78b313b33caf6cf34f900169d5b5fa11072a0418f05de1

See more details on using hashes here.

Provenance

The following attestation bundles were made for casty-0.7.0.tar.gz:

Publisher: publish.yml on gabfssilva/casty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file casty-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: casty-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 88.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for casty-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f48b23a4cff4b8603f63366f1e84d03550e8bfc4a6a778560121d637857d06c
MD5 d9bf6928ba104d7571c57fef775a80c4
BLAKE2b-256 5ed7b7433129169e54cfa8686838fb70a21e6f0c57671b54d7399b07e85d4cb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for casty-0.7.0-py3-none-any.whl:

Publisher: publish.yml on gabfssilva/casty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page