Python client for Zeebe workflow engine
Pyzeebe
pyzeebe is a python grpc client for Zeebe.
Zeebe version support:
| Pyzeebe version | Tested Zeebe versions | | :-------------: | ---------------------- | | 4.x.x | 8.5, 8.6, 8.7, 8.8 | | 3.x.x | 1.0.0 | | 2.x.x | 0.23, 0.24, 0.25, 0.26 | | 1.x.x | 0.23, 0.24 |
Getting Started
To install:
pip install pyzeebe
For full documentation please visit: https://camunda-community-hub.github.io/pyzeebe/
Usage
Worker
The ZeebeWorker class gets jobs from the gateway and runs them.
import asyncio
from pyzeebe import ZeebeWorker, Job, JobController, createinsecurechannel
channel = createinsecurechannel(grpc_address="localhost:26500") # Create grpc channel worker = ZeebeWorker(channel) # Create a zeebe worker
async def onerror(exception: Exception, job: Job, jobcontroller: JobController): """ on_error will be called when the task fails """ print(exception) await jobcontroller.seterror_status(job, f"Failed to handle job {job}. Error: {str(exception)}")
@worker.task(tasktype="example", exceptionhandler=on_error) def example_task(input: str) -> dict: return {"output": f"Hello world, {input}!"}
@worker.task(tasktype="example2", exceptionhandler=on_error) async def anotherexampletask(name: str) -> dict: # Tasks can also be async return {"output": f"Hello world, {name} from async task!"}
loop = asyncio.getrunningloop() loop.rununtilcomplete(worker.work()) # Now every time that a task with type example or example2 is called, the corresponding function will be called
Stop a worker:
await zeebe_worker.stop() # Stops worker after all running jobs have been completed
Client
from pyzeebe import ZeebeClient, createinsecurechannel
Create a zeebe client
channel = createinsecurechannel(grpc_address="localhost:26500")
zeebe_client = ZeebeClient(channel)
Run a Zeebe process instance
processinstancekey = await zeebeclient.runprocess(bpmnprocessid="My zeebe process", variables={})
Run a process and receive the result
processinstancekey, processresult = await zeebeclient.runprocesswith_result(
bpmnprocessid="My zeebe process",
timeout=10000
)
Deploy a BPMN process definition
await zeebeclient.deployresource("process.bpmn")
Cancel a running process
await zeebeclient.cancelprocessinstance(processinstance_key=12345)
Publish message
await zeebeclient.publishmessage(name="message_name", correlati)
Tests
Use the package manager pip to install pyzeebe
pytest tests/unit
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
License
We use the MIT license, see LICENSE.md for details