Skip to main content

Zeebe client api

Project description

Compatible with: Camunda Platform 8

Coverage Status Test pyzeebe Integration test pyzeebe

GitHub tag (latest by date) PyPI PyPI - Python Version

Pyzeebe

pyzeebe is a python grpc client for Zeebe.

Zeebe version support:

Pyzeebe version Tested Zeebe versions
4.x.x 8.2, 8.3, 8.4, 8.5
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, create_insecure_channel


channel = create_insecure_channel(grpc_address="localhost:26500") # Create grpc channel
worker = ZeebeWorker(channel) # Create a zeebe worker


async def on_error(exception: Exception, job: Job, job_controller: JobController):
    """
    on_error will be called when the task fails
    """
    print(exception)
    await job_controller.set_error_status(job, f"Failed to handle job {job}. Error: {str(exception)}")


@worker.task(task_type="example", exception_handler=on_error)
def example_task(input: str) -> dict:
    return {"output": f"Hello world, {input}!"}


@worker.task(task_type="example2", exception_handler=on_error)
async def another_example_task(name: str) -> dict: # Tasks can also be async
    return {"output": f"Hello world, {name} from async task!"}

loop = asyncio.get_running_loop()
loop.run_until_complete(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, create_insecure_channel

# Create a zeebe client
channel = create_insecure_channel(grpc_address="localhost:26500")
zeebe_client = ZeebeClient(channel)

# Run a Zeebe process instance
process_instance_key = await zeebe_client.run_process(bpmn_process_id="My zeebe process", variables={})

# Run a process and receive the result
process_instance_key, process_result = await zeebe_client.run_process_with_result(
    bpmn_process_id="My zeebe process",
    timeout=10000
)

# Deploy a BPMN process definition
await zeebe_client.deploy_resource("process.bpmn")

# Cancel a running process
await zeebe_client.cancel_process_instance(process_instance_key=12345)

# Publish message
await zeebe_client.publish_message(name="message_name", correlation_key="some_id")

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyzeebe-4.5.0.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

pyzeebe-4.5.0-py3-none-any.whl (70.8 kB view details)

Uploaded Python 3

File details

Details for the file pyzeebe-4.5.0.tar.gz.

File metadata

  • Download URL: pyzeebe-4.5.0.tar.gz
  • Upload date:
  • Size: 55.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1021-azure

File hashes

Hashes for pyzeebe-4.5.0.tar.gz
Algorithm Hash digest
SHA256 90aa49f013fbc75b65e48ce3c192a03f228f5651067a2e790ea05421ca535833
MD5 1e46cb0a053140bea91e54756a03ec65
BLAKE2b-256 fb28e32c0c18db5de67e805137f724a5acfde8ab18c78e44d504f59bf1d6cfa8

See more details on using hashes here.

File details

Details for the file pyzeebe-4.5.0-py3-none-any.whl.

File metadata

  • Download URL: pyzeebe-4.5.0-py3-none-any.whl
  • Upload date:
  • Size: 70.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-1021-azure

File hashes

Hashes for pyzeebe-4.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6751d7fe40e93b57bdf820f375090551a6316cc6040cb6a0f7d2688b56a87187
MD5 7e8f40d09bbd0dd79820a2374838ffab
BLAKE2b-256 f1fd9df0df5ab00f57893f6d6f180ad084ed82b04669f19279df9693e85ebc16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page