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.

There APIs can be imported directly from the chorus top-level package.

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 run, spawn_server

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.2

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.2
File Size Uploaded Provenance Actions
chorus_actors-0.1.2.tar.gz 9.8 kB Without provenance Details for chorus_actors-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 23.3 kB

Release files / chorus_actors-0.1.2.tar.gz

Download URL chorus_actors-0.1.2.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
107ea401a40b91b552db62cab525592716019252e8405bff95668467c573bf4b
BLAKE2b-256 checksum
How to use checksums
5d6d4c8fe8ee90c693c3d6dd4acf5027401c31f6b0d898780957896d63038191
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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.2-py3-none-any.whl

Download URL chorus_actors-0.1.2-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
117d51e3d55f706b26367333298c6d66d4a71f2af01e56b96a6f614ec057096e
BLAKE2b-256 checksum
How to use checksums
aa314c4008f93bc73f08a109e2561d31fb0614ce31958082acb28d614a865765
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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.2

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