Skip to main content

Chorus - A simple actor library for Python

Chorus is a Python package that provides a version of the Actor model of concurrency. It is built ontop of Python's built-in threading package and each Actor has its own thread. Actors can send and recieve messges from other actors as well as spawn new Actors.

The package has three layers:

  • chorus.runtime a minimal API for managing Python threads using the Actor model, roughly based on Erlangs API.
  • chorus.messaging provides message base classes and request/reply exchanges with tell and ask.
  • chorus.dispatch provides an object-oriented API for sending and receiving messages between actors.

Import the public APIs directly from chorus:

from chorus import receive, run, spawn, ask, tell, spawn_server

The top-level package brings together the runtime, messaging, and dispatch APIs. Internal modules import directly from defining modules to avoid circular imports.

Examples

Here is an example of the chorus.runtime API in action. One actor spawns another and that one echos back every messaged if the message has a sender_id, otherwise is ends.

from chorus import me, receive, run, send, spawn


def echo():
    match receive():
        case (sender_id, msg):
            send(sender_id, msg)
            echo()
        case _:
            print("Echo: any other message means end.")


def main():
    echo_id = spawn(echo)
    send(echo_id, (me(), "hello"))
    msg = receive()
    print(f"received: {msg}")
    send(echo_id, "end")


if __name__ == "__main__":
    run(main)

Here is that same echo example using the chorus.dispatch API:

from typing import Any
from chorus import spawn_server, run

class EchoHandler:
    def echo(self, message: Any) -> Any:
        return message

def main():
    proxy = spawn_server(EchoHandler())
    result = proxy.ask.echo("hello")
    print(result)  # 'hello'
    proxy.kill()

if __name__ == "__main__":
    run(main)

Installation

Chorus requires Python 3.12 or later. The package name on Pypi is chorus-actors. To add it to a project using uv:

uv add chorus-actors

Or install it with pip:

python -m pip install chorus-actors

Documentation

The documentation can be found here.

Examples:

The examples are grouped by layer:

  • runtime: actors, raw messages, main-thread execution, and drawing.
  • messaging: message subclasses and request/reply exchanges.
  • dispatch: counters, proxies, and GUI event-loop integration.

To run an example from the repository root:

uv run examples/dispatch/proxy_counter.py

License

This project is licensed under the MIT licence.

Metadata

Release files for chorus-actors 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chorus-actors 0.1.4
File Size Uploaded Provenance Actions
chorus_actors-0.1.4.tar.gz 10.3 kB Without provenance Details for chorus_actors-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chorus-actors 0.1.4
File Interpreter ABI Platform Actions
chorus_actors-0.1.4-py3-none-any.whl Python 3 none any Details for chorus_actors-0.1.4-py3-none-any.whl

Total release size: 24.2 kB

Release files / chorus_actors-0.1.4.tar.gz

Download URL chorus_actors-0.1.4.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a5bdcf83268ad5a6c492809214519284ce1060f225608a00b8f6ba7cb41bf9de
BLAKE2b-256 checksum
How to use checksums
41aae0b77312929fa529c515b6f63b667cc4c620598f05c499bc96ea1437a140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / chorus_actors-0.1.4-py3-none-any.whl

Download URL chorus_actors-0.1.4-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ddd0bbd0b5c784bcafff109bdee9ce8a9c4254f9897ac4f4b3643683335e1cc6
BLAKE2b-256 checksum
How to use checksums
3120abebff6d4684020c44c906008e8e6f58e4e36af1da6ac20062fcdb95cb0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for chorus-actors 0.1.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page