Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 88 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,85 @@

## Introduction

A highlevel interface for the dispatch API.
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.

See [the documentation](https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch) for more information.
The main entry point is the [`Dispatcher`][dispatcher-class] class, which
provides channels for receiving dispatch lifecycle events and running status
updates, allowing you to build reactive applications that respond to dispatch
state changes.

## Usage
## Supported Platforms

The following platforms are officially supported (tested):

- **Python:** 3.11
- **Operating System:** Ubuntu Linux 20.04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're testjing against 24.04 now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to Ubuntu Linux 24.04. Commit: 74e2bb1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I saw this one, but all projects are the same so I thought maybe we leave it for another mass update, but maybe we can also just add it to the issue as something to do 👍

Interesting that your review also triggers a copilot session, even if you didn't assign copilot to the PR yourself. It is a bit annoying, maybe if we unassign copilot it stops doing that.

- **Architectures:** amd64, arm64

## Installation

### Using pip

The [`Dispatcher` class](https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher), the main entry point for the API, provides two channels:
You can install the package from PyPI:

* [Lifecycle events](https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.lifecycle_events): A channel that sends a message whenever a [Dispatch][frequenz.dispatch.Dispatch] is created, updated or deleted.
* [Running status change](https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.running_status_change): 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.
```bash
python3 -m pip install frequenz-dispatch
```

### Using pyproject.toml

Add the dependency to your `pyproject.toml` file:

```toml
[project]
dependencies = [
"frequenz-dispatch >= 0.10.1, < 0.11",
]
```

> [!NOTE]
> We recommend pinning the dependency to the latest version for programs,
> like `"frequenz-dispatch == 0.10.1"`, and specifying a version range
> spanning one major version for libraries, like
> `"frequenz-dispatch >= 0.10.1, < 0.11"`. We follow [semver](https://semver.org/).

## Quick Start

The `frequenz-dispatch` library provides a high-level interface to interact
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is repeated, first appearing above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant description sentence from the Quick Start section. Commit: 74e2bb1

with the dispatch API. Here's a minimal example to get you started:

```python
import os
from frequenz.dispatch import Dispatcher

async def main():
# Configure connection to dispatch API
url = os.getenv("DISPATCH_API_URL", "grpc://your-dispatch-url.com")
key = os.getenv("DISPATCH_API_KEY", "your-api-key")
microgrid_id = 1

# Create and use the dispatcher
async with Dispatcher(
microgrid_id=microgrid_id,
server_url=url,
key=key,
) as dispatcher:
# Your dispatch logic here
print("Dispatcher ready!")
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also repeated.. though I am not sure if that is a problem or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the main entry part)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant "main entry point" reference from line 78. Commit: 0bcd222

The [`Dispatcher` class][dispatcher-class], the main entry point for the API,
provides two channels:

* [Lifecycle events][lifecycle-events]: A channel that sends a message whenever
a [Dispatch][frequenz.dispatch.Dispatch] is created, updated or deleted.
* [Running status change][running-status-change]: 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 using the running status change channel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct, the example shows the managing of an actor which internally uses the running status channel.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the section title to "Example managing actors with dispatch events" which better describes what the example demonstrates. Commit: 0bcd222


Expand All @@ -26,12 +95,16 @@ from datetime import timedelta

from frequenz.dispatch import Dispatcher, DispatchInfo, MergeByType

async def create_actor(dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]) -> Actor:
async def create_actor(
dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
) -> Actor:
return MagicMock(dispatch=dispatch, receiver=receiver)

async def run():
url = os.getenv("DISPATCH_API_URL", "grpc://dispatch.url.goes.here.example.com")
key = os.getenv("DISPATCH_API_KEY", "some-key")
url = os.getenv(
"DISPATCH_API_URL", "grpc://dispatch.url.goes.here.example.com"
)
key = os.getenv("DISPATCH_API_KEY", "some-key")

microgrid_id = 1

Expand All @@ -50,13 +123,14 @@ async def run():
await dispatcher
```

## Supported Platforms
[dispatcher-class]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher
[lifecycle-events]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.lifecycle_events
[running-status-change]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.running_status_change

The following platforms are officially supported (tested):
## Documentation

- **Python:** 3.11
- **Operating System:** Ubuntu Linux 20.04
- **Architectures:** amd64, arm64
For complete API documentation, examples, and advanced usage patterns, see
[the documentation](https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch).

## Contributing

Expand Down
Loading