Dispatch Highlevel Interface
Introduction
The frequenz-dispatch library provides a high-level Python interface for
interacting with the Frequenz Dispatch API. This library enables you to
manage and monitor dispatch operations in microgrids, including lifecycle
events and running status changes of dispatch operations.
The main entry point is the Dispatcher class, which
provides methods for receiving dispatch lifecycle events and running status
updates, allowing you to build reactive applications that respond to dispatch
state changes.
Supported Platforms
The following platforms are officially supported (tested):
- Python: 3.11, 3.13
- Operating System: Ubuntu Linux 24.04
- Architectures: amd64, arm64
Installation
Using pip
You can install the package from PyPI:
python3 -m pip install frequenz-dispatch
Using pyproject.toml
Add the dependency to your pyproject.toml file:
[project]
dependencies = [
"frequenz-dispatch >= 1.0.1, < 2",
]
Quick Start
Here's a minimal example to get you started with lifecycle events:
import asyncio
import os
from frequenz.dispatch import Created, Deleted, Dispatcher, Updated
async def main() -> None:
url = os.getenv("DISPATCH_API_URL", "grpc://localhost:50051")
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "my-api-key")
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
microgrid_id = 1
async with Dispatcher(
microgrid_id=microgrid_id,
server_url=url,
auth_key=auth_key,
sign_secret=sign_secret,
) as dispatcher:
events_receiver = dispatcher.new_lifecycle_events_receiver("MY_TYPE")
async for event in events_receiver:
match event:
case Created(dispatch):
print(f"Created: {dispatch}")
case Updated(dispatch):
print(f"Updated: {dispatch}")
case Deleted(dispatch):
print(f"Deleted: {dispatch}")
asyncio.run(main())
The Dispatcher class provides two receiver methods:
new_lifecycle_events_receiver(): Returns a receiver that sends a message whenever a Dispatch is created, updated or deleted.new_running_state_event_receiver(): Returns a receiver that sends a dispatch message whenever a dispatch is ready to be executed according to the schedule or the running status of the dispatch changed in a way that could potentially require the actor to start, stop or reconfigure itself.
Example managing actors with dispatch events
import os
from datetime import timedelta
from unittest.mock import MagicMock
from frequenz.channels import Receiver
from frequenz.sdk.actor import Actor
from frequenz.dispatch import Dispatcher, DispatchInfo, MergeByType
async def create_actor(
dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
) -> Actor:
return MagicMock(dispatch=dispatch, receiver=receiver)
async def run() -> None:
url = os.getenv(
"DISPATCH_API_URL", "grpc://dispatch.api.example.com:50051"
)
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "my-api-key")
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
microgrid_id = 1
async with Dispatcher(
microgrid_id=microgrid_id,
server_url=url,
auth_key=auth_key,
sign_secret=sign_secret,
) as dispatcher:
await dispatcher.start_managing(
dispatch_type="EXAMPLE_TYPE",
actor_factory=create_actor,
merge_strategy=MergeByType(),
retry_interval=timedelta(seconds=10)
)
await dispatcher
Documentation
For complete API documentation, examples, and advanced usage patterns, see the documentation.
Contributing
If you want to know how to build this project and contribute to it, please check out the Contributing Guide.
Metadata
Release files for frequenz-dispatch 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| frequenz_dispatch-1.0.4.tar.gz | 25.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| frequenz_dispatch-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.4 kB
Release files / frequenz_dispatch-1.0.4.tar.gz
| Download URL | frequenz_dispatch-1.0.4.tar.gz |
|---|---|
| Size | 25.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff077348a6a4f1c1740120a17ab5b9de4d64f651839208e259f9319a06a25c3f
|
|
BLAKE2b-256 checksum How to use checksums |
e371206740948d3b134953f3d8ee8a557f72b4bbc44128b64614dbbbc1b068c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / frequenz_dispatch-1.0.4-py3-none-any.whl
| Download URL | frequenz_dispatch-1.0.4-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1cf3ba84499fac890bf44e534f74f4ec7ebf1779fa108497e4813edc3ada95fb
|
|
BLAKE2b-256 checksum How to use checksums |
05fe8030f967f72bd02976205ff1d6538bf4a01a40b615015533868af018bd45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency log