Skip to main content

larzactor

Actor-model concurrency without locks. Pure Python, zero dependencies.

An actor owns its state and a mailbox; it processes one message at a time in its own thread, so its state is never touched by two threads at once - no locks, no data races, by construction. You talk to actors only by sending messages.

from larzactor import Actor, ActorSystem

class Counter(Actor):
    def __init__(self):
        self.count = 0
    def receive(self, message):
        if message == "inc":
            self.count += 1
        elif message == "get":
            return self.count

system = ActorSystem()
ref = system.spawn(Counter)
for _ in range(1000):
    ref.tell("inc")
ref.ask("get")            # 1000 - exact, even under concurrent senders
system.shutdown()

Why

  • Concurrency you can reason about. State lives inside an actor and is only ever touched by that actor's thread, so you write ordinary sequential code with no locks - and get correct results even when many threads send at once (the tests hammer one actor from 4 threads and count is exact).
  • tell and ask. tell is fire-and-forget; ask sends and waits for the handler's return value (re-raising any exception it threw).
  • Supervision. A handler that raises doesn't kill the actor - a supervisor on_error hook is notified and the actor keeps processing.
  • Zero dependencies. Plain threads + queues.

Install

pip install larzactor

Usage

from larzactor import Actor, ActorSystem

system = ActorSystem(on_error=lambda ref, msg, exc: log(exc))

ref = system.spawn(MyActor, *init_args)      # Actor subclass
ref = system.spawn(lambda msg: msg * 2)      # or a plain callable

ref.tell(message)                            # fire-and-forget
result = ref.ask(query, timeout=5)           # request/response
ref.stop()
system.shutdown()

Tests

python -m unittest discover -s tests -v   # 8 tests incl. a no-lost-updates race test

The Larz stack

One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.

License

MIT (c) larz-scripter

Metadata

Release files for larzactor 0.1.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 larzactor 0.1.0
File Size Uploaded Provenance
larzactor-0.1.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 10.8 kB

Release files / larzactor-0.1.0.tar.gz

Download URL larzactor-0.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9f39b8e02983eb455b81d1b2717160cdd2277968358fe03f894ad10f124c866a
BLAKE2b-256 checksum
How to use checksums
b9fe0f776f913aa21e978646e41c3678d9fe9650a3fad62f73974c2cd9977c18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / larzactor-0.1.0-py3-none-any.whl

Download URL larzactor-0.1.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
feebf14edfa72038645fb349984e68de13bda4dbabf52ec40e2002a9af9d3768
BLAKE2b-256 checksum
How to use checksums
2d0d23fa05f4dec894fd134d3901686651f3231b83c9f2bfe091c38586e609c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for larzactor 0.1.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.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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