ChopFlow Python Client
A Python worker + producer SDK for ChopFlow, the distributed task
queue in Rust. The broker and all execution logic live in Rust; this SDK lets you
define and run task handlers in Python and enqueue tasks from Python, speaking
gRPC to the broker over the contract in broker/proto/chopflow.proto.
Build status: Verified —
pytestpasses (Python 3.12 + grpcio 1.83) and the examples round-trip end-to-end against the Rust broker (Python producer enqueues an echo task → Python worker acks →AsyncResult.get()returnsCOMPLETED).
Requirements
- Python 3.10+
- The Rust broker binary (
chopflow_broker) running somewhere reachable. Build it withcargo build -p chopflow_brokerfrom the repo root.
Install
The SDK is not yet published to PyPI; install it editable from source:
cd clients/python
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
The generated gRPC stubs (src/chopflow/_generated/) are committed, so no protoc
toolchain is required to install or use the SDK. Regenerate them only when the proto
changes:
python generate.py # reads ../../broker/proto/chopflow.proto
Usage
Worker — define and run handlers in Python
from chopflow import ChopFlowWorker, task
@task("resize_image")
def resize(payload):
# ...your logic; return something JSON-serializable...
return {"status": "ok", "resized": payload}
worker = (
ChopFlowWorker.builder()
.broker("localhost:8000")
.tags("image")
.resources("cpu", 2)
.build()
)
# `resize_image` was registered via the @task decorator above.
worker.register("ping", lambda p: {"pong": True}) # or register callables directly
worker.start_and_await() # blocks until Ctrl+C
The worker registers with the broker, sends heartbeats, polls FetchTasks, executes
the matching handler, and acknowledges each task. A handler that raises is acked as a
failure and the broker applies its retry/dead-letter policy. Tasks with no registered
handler fall back to the worker's default handler (override via
worker.register_default(...)).
Producer — enqueue tasks and await results
from chopflow import ChopFlowClient
with ChopFlowClient.connect("localhost:8000") as client:
result = (
client.enqueue("resize_image")
.payload({"path": "/img/a.png", "w": 128})
.tags("image")
.max_retries(2)
.priority(5) # higher = claimed before lower (default 0)
.enqueue()
)
task = result.get(timeout=60) # blocks until terminal
print(task.status_name, task.result)
AsyncResult.get() polls GetTaskStatus until the task reaches a terminal state
(COMPLETED, FAILED, DEADLETTERED, CANCELLED). By default it raises
TaskFailedError if the task did not complete; pass raise_on_failure=False to get
the terminal Task back instead. It raises TaskTimeoutError if the deadline elapses.
Schedules
from chopflow import ChopFlowClient
from chopflow.models import OverlapPolicy
with ChopFlowClient.connect("localhost:8000") as client:
sid = client.create_cron_schedule(
"nightly", "build", "0 9 * * *", tags=["ci"], overlap=OverlapPolicy.OVERLAP_SKIP
)
print(client.list_schedules())
client.delete_schedule(sid)
Examples
examples/producer.py— enqueue an echo task and print the result.examples/echo_worker.py— register anechohandler and run until Ctrl+C.
Tests
cd clients/python
pip install -e ".[dev]"
pytest # builds the broker once, then runs 14 integration tests
The test suite builds the Rust broker on an ephemeral port with in-memory storage and exercises the full SDK: enqueue/get, polling, cancellation, failure dead-lettering, schedule CRUD, and worker handler dispatch.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chopflow-0.1.0.tar.gz.
File metadata
- Download URL: chopflow-0.1.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a35087b763d9589d93bf35e4c8fa82aea8d3e150887da345f53cc5e5ac5d898
|
|
| MD5 |
b4a2d0ecb921cb9484a293bcde60add2
|
|
| BLAKE2b-256 |
1285b69e42c225c39c01741dc49f622191ed548a0b7b4e600fc738e4218a4f5c
|
Provenance
The following attestation bundles were made for chopflow-0.1.0.tar.gz:
Publisher:
release.yml on ricardoleal20/ChopFlow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chopflow-0.1.0.tar.gz -
Subject digest:
2a35087b763d9589d93bf35e4c8fa82aea8d3e150887da345f53cc5e5ac5d898 - Sigstore transparency entry: 2788465360
- Sigstore integration time:
-
Permalink:
ricardoleal20/ChopFlow@647df02ca64975437f0dcb18f8ac982c441c1b86 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ricardoleal20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@647df02ca64975437f0dcb18f8ac982c441c1b86 -
Trigger Event:
push
-
Statement type:
File details
Details for the file chopflow-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chopflow-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
869131bd465a5405b477c81aa89de5b737229e8370217d6f879a9ce2bf22fdb8
|
|
| MD5 |
a29a9a8923c621a9155a9c6962364cb8
|
|
| BLAKE2b-256 |
47e5623758ba8e23c46c1c2dd629c106afa46a8720d0f41fda4d31c890b3024c
|
Provenance
The following attestation bundles were made for chopflow-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ricardoleal20/ChopFlow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chopflow-0.1.0-py3-none-any.whl -
Subject digest:
869131bd465a5405b477c81aa89de5b737229e8370217d6f879a9ce2bf22fdb8 - Sigstore transparency entry: 2788465431
- Sigstore integration time:
-
Permalink:
ricardoleal20/ChopFlow@647df02ca64975437f0dcb18f8ac982c441c1b86 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ricardoleal20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@647df02ca64975437f0dcb18f8ac982c441c1b86 -
Trigger Event:
push
-
Statement type: