Skip to content

Commit aa6f5a2

Browse files
Copilotllucax
andcommitted
Add Quick Start and Installation sections to README.md
Co-authored-by: llucax <1031485+llucax@users.noreply.github.com>
1 parent 12a5d3d commit aa6f5a2

File tree

1 file changed

+75
-6
lines changed

1 file changed

+75
-6
lines changed

README.md

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,52 @@
88

99
A highlevel interface for the dispatch API.
1010

11-
See [the documentation](https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch) for more information.
11+
See [the documentation](https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch)
12+
for more information.
13+
14+
## Quick Start
15+
16+
The `frequenz-dispatch` library provides a high-level interface to interact
17+
with the dispatch API. Here's a minimal example to get you started:
18+
19+
```python
20+
import os
21+
from datetime import timedelta
22+
from frequenz.dispatch import Dispatcher
23+
24+
async def main():
25+
# Configure connection to dispatch API
26+
url = os.getenv("DISPATCH_API_URL", "grpc://your-dispatch-url.com")
27+
key = os.getenv("DISPATCH_API_KEY", "your-api-key")
28+
microgrid_id = 1
29+
30+
# Create and use the dispatcher
31+
async with Dispatcher(
32+
microgrid_id=microgrid_id,
33+
server_url=url,
34+
key=key,
35+
) as dispatcher:
36+
# Your dispatch logic here
37+
print("Dispatcher ready!")
38+
```
39+
40+
For complete examples and advanced usage, see the [Usage](#usage) section below.
1241

1342
## Usage
1443

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:
44+
The [`Dispatcher` class][dispatcher-class], the main entry point for the API,
45+
provides two channels:
1646

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.
47+
* [Lifecycle events][lifecycle-events]: A channel that sends a message whenever
48+
a [Dispatch][frequenz.dispatch.Dispatch] is created, updated or deleted.
49+
* [Running status change][running-status-change]: Sends a dispatch message
50+
whenever a dispatch is ready to be executed according to the schedule or the
51+
running status of the dispatch changed in a way that could potentially
52+
require the actor to start, stop or reconfigure itself.
53+
54+
[dispatcher-class]: https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher
55+
[lifecycle-events]: https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.lifecycle_events
56+
[running-status-change]: https://frequenz-floss.github.io/frequenz-dispatch-python/v0.1/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.running_status_change
1957

2058
### Example using the running status change channel
2159

@@ -26,11 +64,15 @@ from datetime import timedelta
2664

2765
from frequenz.dispatch import Dispatcher, DispatchInfo, MergeByType
2866

29-
async def create_actor(dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]) -> Actor:
67+
async def create_actor(
68+
dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
69+
) -> Actor:
3070
return MagicMock(dispatch=dispatch, receiver=receiver)
3171

3272
async def run():
33-
url = os.getenv("DISPATCH_API_URL", "grpc://dispatch.url.goes.here.example.com")
73+
url = os.getenv(
74+
"DISPATCH_API_URL", "grpc://dispatch.url.goes.here.example.com"
75+
)
3476
key = os.getenv("DISPATCH_API_KEY", "some-key")
3577

3678
microgrid_id = 1
@@ -58,6 +100,33 @@ The following platforms are officially supported (tested):
58100
- **Operating System:** Ubuntu Linux 20.04
59101
- **Architectures:** amd64, arm64
60102

103+
## Installation
104+
105+
### Using pip
106+
107+
You can install the package from PyPI:
108+
109+
```bash
110+
python3 -m pip install frequenz-dispatch
111+
```
112+
113+
### Using pyproject.toml
114+
115+
Add the dependency to your `pyproject.toml` file:
116+
117+
```toml
118+
[project]
119+
dependencies = [
120+
"frequenz-dispatch >= 0.10.1, < 0.11",
121+
]
122+
```
123+
124+
> [!NOTE]
125+
> We recommend pinning the dependency to the latest version for programs,
126+
> like `"frequenz-dispatch == 0.10.1"`, and specifying a version range
127+
> spanning one major version for libraries, like
128+
> `"frequenz-dispatch >= 0.10.1, < 0.11"`. We follow [semver](https://semver.org/).
129+
61130
## Contributing
62131

63132
If you want to know how to build this project and contribute to it, please

0 commit comments

Comments
 (0)