Skip to content

Commit 0839f8e

Browse files
authored
Improve README.md for better project discoverability (#221)
Improves the README based on the suggestions in #166: - Add expanded introduction describing the library purpose - Add Installation section with pip and pyproject.toml examples - Add Quick Start section with minimal working example - Move Supported Platforms section before Installation - Update documentation links to use /latest/ instead of /v0.1/ - Fix long lines using reference-style links - Update Ubuntu version to 24.04 - Update version references to v1.0.1 This is a corrected version of #176 targeting v1.x.x with updated API usage. Fixes #166 Supersedes #176
2 parents 9445c27 + eafafcb commit 0839f8e

File tree

2 files changed

+108
-17
lines changed

2 files changed

+108
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
python:
3737
- "3.11"
3838
- "3.12"
39+
- "3.13"
3940
nox-session:
4041
# To speed things up a bit we use the special ci_checks_max session
4142
# that uses the same venv to run multiple linting sessions
@@ -113,6 +114,7 @@ jobs:
113114
python:
114115
- "3.11"
115116
- "3.12"
117+
- "3.13"
116118
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
117119

118120
steps:

README.md

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,119 @@
66

77
## Introduction
88

9-
A highlevel interface for the dispatch API.
9+
The `frequenz-dispatch` library provides a high-level Python interface for
10+
interacting with the Frequenz Dispatch API. This library enables you to
11+
manage and monitor dispatch operations in microgrids, including lifecycle
12+
events and running status changes of dispatch operations.
1013

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

13-
## Usage
19+
## Supported Platforms
20+
21+
The following platforms are officially supported (tested):
22+
23+
- **Python:** 3.11, 3.13
24+
- **Operating System:** Ubuntu Linux 24.04
25+
- **Architectures:** amd64, arm64
1426

15-
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:
27+
## Installation
1628

17-
* [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.
18-
* [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.
29+
### Using pip
1930

20-
### Example using the running status change channel
31+
You can install the package from PyPI:
32+
33+
```bash
34+
python3 -m pip install frequenz-dispatch
35+
```
36+
37+
### Using pyproject.toml
38+
39+
Add the dependency to your `pyproject.toml` file:
40+
41+
```toml
42+
[project]
43+
dependencies = [
44+
"frequenz-dispatch >= 1.0.1, < 2",
45+
]
46+
```
47+
48+
> [!NOTE]
49+
> We recommend pinning the dependency to the latest version for programs,
50+
> like `"frequenz-dispatch == 1.0.1"`, and specifying a version range
51+
> spanning one major version for libraries, like
52+
> `"frequenz-dispatch >= 1.0.1, < 2"`. We follow [semver](https://semver.org/).
53+
54+
## Quick Start
55+
56+
Here's a minimal example to get you started with lifecycle events:
57+
58+
```python
59+
import asyncio
60+
import os
61+
62+
from frequenz.dispatch import Created, Deleted, Dispatcher, Updated
63+
64+
async def main() -> None:
65+
url = os.getenv("DISPATCH_API_URL", "grpc://localhost:50051")
66+
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "my-api-key")
67+
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
68+
microgrid_id = 1
69+
70+
async with Dispatcher(
71+
microgrid_id=microgrid_id,
72+
server_url=url,
73+
auth_key=auth_key,
74+
sign_secret=sign_secret,
75+
) as dispatcher:
76+
events_receiver = dispatcher.new_lifecycle_events_receiver("MY_TYPE")
77+
78+
async for event in events_receiver:
79+
match event:
80+
case Created(dispatch):
81+
print(f"Created: {dispatch}")
82+
case Updated(dispatch):
83+
print(f"Updated: {dispatch}")
84+
case Deleted(dispatch):
85+
print(f"Deleted: {dispatch}")
86+
87+
asyncio.run(main())
88+
```
89+
90+
The [`Dispatcher` class][dispatcher-class] provides two receiver methods:
91+
92+
* [`new_lifecycle_events_receiver()`][lifecycle-events]: Returns a receiver
93+
that sends a message whenever a Dispatch is created, updated or deleted.
94+
* [`new_running_state_event_receiver()`][running-status-change]: Returns a
95+
receiver that sends a dispatch message whenever a dispatch is ready to be
96+
executed according to the schedule or the running status of the dispatch
97+
changed in a way that could potentially require the actor to start, stop or
98+
reconfigure itself.
99+
100+
### Example managing actors with dispatch events
21101

22102
```python
23103
import os
24-
from unittest.mock import MagicMock
25104
from datetime import timedelta
105+
from unittest.mock import MagicMock
106+
107+
from frequenz.channels import Receiver
108+
from frequenz.sdk.actor import Actor
26109

27110
from frequenz.dispatch import Dispatcher, DispatchInfo, MergeByType
28111

29-
async def create_actor(dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]) -> Actor:
112+
async def create_actor(
113+
dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
114+
) -> Actor:
30115
return MagicMock(dispatch=dispatch, receiver=receiver)
31116

32-
async def run():
33-
url = os.getenv("DISPATCH_API_URL", "grpc://dispatch.url.goes.here.example.com")
34-
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "some-key")
117+
async def run() -> None:
118+
url = os.getenv(
119+
"DISPATCH_API_URL", "grpc://dispatch.api.example.com:50051"
120+
)
121+
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "my-api-key")
35122
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
36123

37124
microgrid_id = 1
@@ -52,13 +139,15 @@ async def run():
52139
await dispatcher
53140
```
54141

55-
## Supported Platforms
142+
## Documentation
56143

57-
The following platforms are officially supported (tested):
144+
For complete API documentation, examples, and advanced usage patterns, see
145+
[the documentation][docs].
58146

59-
- **Python:** 3.11
60-
- **Operating System:** Ubuntu Linux 20.04
61-
- **Architectures:** amd64, arm64
147+
[dispatcher-class]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher
148+
[lifecycle-events]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.new_lifecycle_events_receiver
149+
[running-status-change]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.new_running_state_event_receiver
150+
[docs]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/
62151

63152
## Contributing
64153

0 commit comments

Comments
 (0)