casty
casty is a typed virtual actor framework for concurrent and distributed programming in Python.
As Hewitt describes, an actor is a primitive of concurrent computation that communicates with other actors through asynchronous messages. Upon receiving a message, an actor may:
- Send messages to actors whose addresses it knows.
- Create new actors.
- Determine how it will handle the next message it receives.
In casty, actors are defined as async Python functions decorated with @actor. Each function defines an actor type, and each (actor type, key) identifies a virtual actor with its own state and mailbox.
An actor processes one message at a time. The runtime manages activation and deactivation, and the same actor code can run in a single process or across a cluster with state replication.
Documentation · Examples · Issues
Installation
pip install casty
Or add it to a project with uv:
uv add casty
Requires Python 3.12 or later. The runtime is written in Rust. Installing from source requires Rust 1.90 or later.
A first actor
This counter updates its state and replies with the new total:
import asyncio
from dataclasses import dataclass
from casty import ActorSystem, Askable, Context, actor
@dataclass(frozen=True)
class Add:
amount: int
@dataclass(frozen=True)
class Get(Askable[int]): pass
@actor(initial=0)
async def counter(ctx: Context[int, Add | Get]) -> None:
async for msg in ctx.inbox:
match msg:
case Add(amount):
await ctx.state.set(ctx.state.value + amount)
case Get():
msg.reply_to.tell(ctx.state.value)
async def main() -> None:
async with ActorSystem() as system:
views = system.ref(counter, "page-views")
views.tell(Add(1))
print(await views.ask(Get()))
views.tell(Add(2))
print(await views.ask(Get()))
asyncio.run(main())
Output:
1
3
Context[int, Add | Get] declares the state and message types. Askable[int] declares the reply type, and initial=0 provides the initial state of each counter.
system.ref(counter, "page-views") addresses one counter by its key. A different key has independent state. ask waits for a reply; tell sends a message without waiting for one.
State, messages and replies are serialized even within one process. Use immutable values, such as frozen dataclasses, tuples and frozensets.
An await inside the message loop delays the next message for that actor. To handle other asynchronous work while continuing to receive messages, use ctx.to_self or ctx.ask. Blocking calls can run through asyncio.to_thread.
Running a cluster
To join a cluster, configure the node's listening address, advertised address and seed nodes. In the example above, import Cluster and replace main with:
from casty import Cluster
async def main() -> None:
cluster = Cluster(
bind="0.0.0.0:7400",
advertise="10.0.0.5:7400",
seeds=("10.0.0.4:7400",),
)
async with ActorSystem(cluster=cluster) as system:
views = system.ref(counter, "page-views")
print(await views.ask(Add(1)))
Every node must have the same actor definitions, at module scope. The runtime routes messages to the node that owns each key and moves actors as nodes join, leave or fail. Placement uses consistent hashing, and membership is maintained through gossip.
By default, each key has up to three replicas, limited by the cluster size, and state writes wait for a majority of replicas to confirm. Both the replica count and the write level are configurable per actor type.
A Client sends messages to the cluster without hosting actors or participating in membership. See the cluster example and client example for runnable programs.
State and persistence
ctx.state.value reads the last saved state. await ctx.state.set(value) replaces it, and await ctx.state.update(change) applies a function and returns the saved result. Both wait for the configured write level to confirm before updating the local value.
State is kept in memory on its replicas. To preserve it across a full cluster restart, configure a store and declare the actor type with durable="write". A confirmed write then also waits for the store.
casty.stores.SQL supports PostgreSQL, MySQL, MariaDB and SQLite. Every node must reach the same stored records. The durable state example demonstrates recovery after stopping the entire cluster.
Schedules and collections
Actors can schedule messages with ctx.schedule. Schedules are saved with actor state and follow the actor when its owner changes.
Collections provides replicated counters, registers, dicts, sets, multimaps, queues, semaphores, locks and barriers over an ActorSystem or a Client. Collections are not durable.
The documentation covers the programming model, runtime implementation and public APIs in numbered chapters. The examples also cover state machines, messages between actors, streams and failure recovery.
Guarantees and limits
- Message delivery is at most once. Messages from one node to one key arrive in order while the owner remains the same.
- With majority writes, confirmed state survives the loss of a minority of replicas. The minority side of a network partition cannot write. With
write="one", an ownership change can lose confirmed writes. - A failed or timed-out operation may have committed.
- Reads are not linearizable. During ownership changes or after a long process pause, an actor may answer from stale state.
- Side effects can repeat after an actor restarts or changes owner.
- Losing every replica loses in-memory state. Use a durable store when state must survive that loss.
- Schedules and leases depend on synchronized node clocks. Schedules can be missed or delivered twice during ownership changes; leases can expire while their holder is still running.
Contributing
Bug reports and pull requests are welcome. For a bug report, include a small reproducer and your Python and casty versions.
To set up the development environment and run the checks:
uv sync
make check
make check runs linting, type checks, the Rust and Python test suites, and documentation checks. After changing Rust code, rebuild the extension with make build. Run make help for the other development commands.
License
MIT.
Metadata
Release files for casty 0.30.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| casty-0.30.2.tar.gz | 377.5 kB | Details |
Built distributions (wheels)
Total release size: 73.2 MB
Release files / casty-0.30.2.tar.gz
| Download URL | casty-0.30.2.tar.gz |
|---|---|
| Size | 377.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6bb4be50411fb089b35a3299eff5b46bd8b8d32323b482d7ed500de0a659df25
|
|
BLAKE2b-256 checksum How to use checksums |
6c6cb1a4ac75ef7470d442084aaaaf210b8b0a2745b4bdac1cf74324e6f34699
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp315-cp315t-win_amd64.whl
| Download URL | casty-0.30.2-cp315-cp315t-win_amd64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.15 CPython 3.15 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ff52a8dded1bf9bb07ab1753f9d533e4421c2c6a6a646b30257dec52e3f7255f
|
|
BLAKE2b-256 checksum How to use checksums |
64fc64107989bc4c4a7a6fca95cebf5fbdef20d7248245b362ce23185283395e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | casty-0.30.2-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.15 CPython 3.15 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
8faaeee44aeaa1d94ab497449f0929a705a40fe428aeecdcbfaeaf980ca19477
|
|
BLAKE2b-256 checksum How to use checksums |
244f58f1ca128d9f6decc13e15d8c59ab920bd588f6b4b4e86172a2b1754fd78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | casty-0.30.2-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.15 CPython 3.15 free-threading Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
9962ae056b6d483bb7c81ebd051e31bbced92e1ad6e5835eb7144d9dcec7972c
|
|
BLAKE2b-256 checksum How to use checksums |
77eb7cae6beb93d8bfa64dacd2a5f04381110d6292c799c27d85a7cd79a2deb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp315-cp315t-macosx_11_0_arm64.whl
| Download URL | casty-0.30.2-cp315-cp315t-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.15 CPython 3.15 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
817fce56fa219eac7011418b7c1ba9731ade8820b471badd12abc190728c2dc9
|
|
BLAKE2b-256 checksum How to use checksums |
05ad706863dea00664077e98cd8cd8aeca85ded91d894d1500da4bebb90c1a2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp315-cp315t-macosx_10_12_x86_64.whl
| Download URL | casty-0.30.2-cp315-cp315t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.15 CPython 3.15 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
66bce511c14deb8c7096c9370c4e0b4480134a3523e43fb3a8aeed4027094ebf
|
|
BLAKE2b-256 checksum How to use checksums |
2fee91fdd9ed82aaa6a44ca1e67d705689236e5a6367b886da24bf602ff3478b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp314-cp314t-win_amd64.whl
| Download URL | casty-0.30.2-cp314-cp314t-win_amd64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b953eebe2d9e9a6c350172bb24d11c178899e91c62da4953e885e520cdff0eab
|
|
BLAKE2b-256 checksum How to use checksums |
6ae414c014a06f49b8570eeca9a6bf70cac10dd2a013a72541ab2c0d40dba151
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | casty-0.30.2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
6666c4cb322afc9cd552503b1bc35948128aace54fdf6631aaa936b72af42709
|
|
BLAKE2b-256 checksum How to use checksums |
250dfb8ee238e61b0e006f3a844b664d354ef335cde71cd689249031cd847ea8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | casty-0.30.2-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
c608625600ea35560a4b1aec909d0c8247911c763584b5932d3ffbb29bb00986
|
|
BLAKE2b-256 checksum How to use checksums |
28f6f908e4eedf32768df7cd863a250daf407f29605c38c767fec7c30e84bf6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | casty-0.30.2-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
32cad44077f26ffaa6ae0a2cc5d65132fa9f1f8edfec21b65dfff9f4fb49b33e
|
|
BLAKE2b-256 checksum How to use checksums |
1eceb949a385b190ec53202b237aa76e3fab3cc0665b02d7c88211948777cb0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | casty-0.30.2-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
73da8054545cd7871e7a3ffe35149eaa90425810d43fc8a2c16ab31f01126efc
|
|
BLAKE2b-256 checksum How to use checksums |
9ec5d35e398a8612be6a8d9883dd0fe31358baad6ab7e078b5865eba1d57519a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp312-abi3-win_amd64.whl
| Download URL | casty-0.30.2-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e6111ec795b07ed5f4e08c0603ddc4af5c142bcf756a4fa4e0d7182bb58a5b5e
|
|
BLAKE2b-256 checksum How to use checksums |
6d7f8d8c247cff048f13c8c3d0dc455f5d317f7b6590b8527da7b0ff0b60f73c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | casty-0.30.2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
aa52c2b835448f51caec43d82d1ebfa513be8d71bd908416c8cad393b7f12a0d
|
|
BLAKE2b-256 checksum How to use checksums |
3fb9c29e5b0aa14297600d7a29532c5457b9290d6075f8404ae825544c922066
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | casty-0.30.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
702886844142e36dff5a75abac09b17b5c9f140992ebbccb4682ae665ec6f9e1
|
|
BLAKE2b-256 checksum How to use checksums |
e2ee9b657744247b4520091a8984078d48edbf25eea9b4de6e6979ebf0815f6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | casty-0.30.2-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
813b89257954f74dc34106bf66f02a0098ab72a7bf737e9f3840163a48534c7a
|
|
BLAKE2b-256 checksum How to use checksums |
483a6d9fe08af11c41f56cac4c7642598bb937d9bd5a762210ad308b58903a8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency logRelease files / casty-0.30.2-cp312-abi3-macosx_10_12_x86_64.whl
| Download URL | casty-0.30.2-cp312-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.12 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
517d707aa82bd3d37a034bf3fc3773a64c51d6b52cd6201347c1f106c0a95e4f
|
|
BLAKE2b-256 checksum How to use checksums |
3619b499cf64ad710a8d251b931dd003ab2a6a1c59dadbac221a7fe623b9a072
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.
Transparency log