Skip to main content

Cleveland

CI PyPI

Simple asyncio-based actors.

Named after Carol Cleveland, the only significant female performer on Monty Python's Flying Circus.

pip install cleveland

Cleveland supports Python 3.11 and newer, has no dependencies, and includes type hints, so type checkers such as mypy check your handlers against its API.

Example usage

import asyncio

from cleveland import BaseActor, Message, QueryMessage


# Define new message classes, and register handlers for them in your actors.
class StringMessage(Message):
    pass


class LengthQuery(QueryMessage):
    pass


# Define actors that respond to Message subclasses with custom behavior.
class PrintActor(BaseActor):
    def __init__(self) -> None:
        super().__init__()
        self.register_handler(StringMessage, self.on_string)
        self.register_handler(LengthQuery, self.on_length)

    async def on_string(self, message: StringMessage) -> None:
        print(message.payload)

    # A query handler's return value is the answer to ask().
    async def on_length(self, message: LengthQuery) -> int:
        return len(message.payload)


async def main() -> None:
    a = BaseActor()
    b = PrintActor()
    b.start()
    for _ in range(3):
        await a.tell(b, StringMessage("Hello world!"))
    print(await a.ask(b, LengthQuery("Hello world!")))  # 12
    await b.stop()


asyncio.run(main())

example.py also shows a TimedBroadcaster.

How actors behave

  • Each actor handles the messages in its inbox one at a time, in the order they arrived. A handler is chosen by the message's exact class.
  • start() must be called while the event loop is running. Messages told before start() wait in the inbox. An actor can only be started once.
  • await actor.stop() handles every message sent before it, then waits for the actor to finish. After stop(), telling the actor anything raises ActorStoppedError. Telling an actor a StopMessage stops it the same way.
  • BaseActor(max_inbox_size=n) bounds the inbox, so tell() waits while it's full. The default, 0, is unbounded.

Errors

  • If a query's handler raises, ask() raises that exception. If a told message's handler raises, the exception is logged to the cleveland logger with its traceback. Either way, the actor carries on with the next message.
  • A message with no registered handler makes ask() raise HandlerNotFoundError. For tell(), it's logged.
  • If an actor dies before answering a query, for example because its task was cancelled, ask() raises ActorStoppedError instead of waiting forever.
  • An ask() that's cancelled or times out doesn't affect the actor.

Broadcasters

BaseBroadcaster(targets=[...]) tells every target the same message with await broadcaster.broadcast(message). Subclass TimedBroadcaster and implement async def _message(self) -> Message to broadcast a message every interval seconds. Stopping a broadcaster doesn't wait for the current interval to finish.

Upgrading from 0.2

Cleveland 0.3 uses async def throughout. @asyncio.coroutine was removed in Python 3.11, so 0.2 can't be imported on any supported Python. To upgrade, write handlers and overrides as async def methods, replace yield from with await, and remove any loop= arguments: actors use the running event loop. See CHANGELOG.md for all changes.

Metadata

Release files for cleveland 0.3.0

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

Source distribution (sdist)

Source distribution for cleveland 0.3.0
File Size Uploaded Provenance Actions
cleveland-0.3.0.tar.gz 12.7 kB With provenance Details for cleveland-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cleveland 0.3.0
File Interpreter ABI Platform Actions
cleveland-0.3.0-py3-none-any.whl Python 3 none any Details for cleveland-0.3.0-py3-none-any.whl

Total release size: 20.3 kB

Release files / cleveland-0.3.0.tar.gz

Download URL cleveland-0.3.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
47dda17d256444ef0cf943581f38c7fdb8b3e0f06a78921560ff2b1833f75a39
BLAKE2b-256 checksum
How to use checksums
2a264f98614da6248c734950eb210d8bdfb033a2d026fd2e84c3906ed3a9bd28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Release files / cleveland-0.3.0-py3-none-any.whl

Download URL cleveland-0.3.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ca105bea6cbc5045dff11ad2cf720de6ec806c41676ccfad19b349c20743773
BLAKE2b-256 checksum
How to use checksums
313f77e46a56451f03cacbbe332eeb9683ac3aed30bb941c9e13abc642bc89f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Security for cleveland 0.3.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cleveland-0.3.0.tar.gz

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 Nov 6, 2026.

Transparency log

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