Skip to content

Commit 72b783c

Browse files
committed
Improve README.md for better project discoverability
- 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 Fixes #166 Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 4ae8a30 commit 72b783c

File tree

1 file changed

+91
-18
lines changed

1 file changed

+91
-18
lines changed

README.md

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,87 @@
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 channels 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
24+
- **Operating System:** Ubuntu Linux 24.04
25+
- **Architectures:** amd64, arm64
26+
27+
## Installation
28+
29+
### Using pip
30+
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:
1457

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:
58+
```python
59+
import asyncio
60+
import os
61+
62+
from frequenz.dispatch import Dispatcher
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+
microgrid_id = 1
68+
69+
async with Dispatcher(
70+
microgrid_id=microgrid_id,
71+
server_url=url,
72+
auth_key=auth_key,
73+
) as dispatcher:
74+
async for event in dispatcher.lifecycle_events:
75+
print(f"Received lifecycle event: {event}")
76+
77+
asyncio.run(main())
78+
```
79+
80+
The [`Dispatcher` class][dispatcher-class] provides two channels:
1681

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.
82+
* [Lifecycle events][lifecycle-events]: A channel that sends a message whenever
83+
a Dispatch is created, updated or deleted.
84+
* [Running status change][running-status-change]: Sends a dispatch message
85+
whenever a dispatch is ready to be executed according to the schedule or the
86+
running status of the dispatch changed in a way that could potentially
87+
require the actor to start, stop or reconfigure itself.
1988

20-
### Example using the running status change channel
89+
### Example managing actors with dispatch events
2190

2291
```python
2392
import os
@@ -26,21 +95,23 @@ from datetime import timedelta
2695

2796
from frequenz.dispatch import Dispatcher, DispatchInfo, MergeByType
2897

29-
async def create_actor(dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]) -> Actor:
98+
async def create_actor(
99+
dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
100+
) -> Actor:
30101
return MagicMock(dispatch=dispatch, receiver=receiver)
31102

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")
35-
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
103+
async def run() -> None:
104+
url = os.getenv(
105+
"DISPATCH_API_URL", "grpc://dispatch.api.example.com:50051"
106+
)
107+
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "my-api-key")
36108

37109
microgrid_id = 1
38110

39111
async with Dispatcher(
40112
microgrid_id=microgrid_id,
41113
server_url=url,
42114
auth_key=auth_key,
43-
sign_secret=sign_secret,
44115
) as dispatcher:
45116
await dispatcher.start_managing(
46117
dispatch_type="EXAMPLE_TYPE",
@@ -52,13 +123,15 @@ async def run():
52123
await dispatcher
53124
```
54125

55-
## Supported Platforms
126+
## Documentation
56127

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

59-
- **Python:** 3.11
60-
- **Operating System:** Ubuntu Linux 20.04
61-
- **Architectures:** amd64, arm64
131+
[dispatcher-class]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher
132+
[lifecycle-events]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.lifecycle_events
133+
[running-status-change]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.running_status_change
134+
[docs]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/
62135

63136
## Contributing
64137

0 commit comments

Comments
 (0)