frequenz-dispatch 1.0.2__tar.gz → 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- frequenz_dispatch-1.0.4/PKG-INFO +228 -0
- frequenz_dispatch-1.0.4/README.md +155 -0
- frequenz_dispatch-1.0.4/RELEASE_NOTES.md +10 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/pyproject.toml +39 -30
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/__init__.py +7 -7
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_actor_dispatcher.py +113 -109
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_bg_service.py +71 -25
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_dispatch.py +7 -18
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_dispatcher.py +41 -36
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_event.py +1 -1
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_merge_strategies.py +29 -8
- frequenz_dispatch-1.0.4/src/frequenz_dispatch.egg-info/PKG-INFO +228 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz_dispatch.egg-info/SOURCES.txt +2 -0
- frequenz_dispatch-1.0.4/src/frequenz_dispatch.egg-info/requires.txt +58 -0
- frequenz_dispatch-1.0.4/src/frequenz_dispatch.egg-info/scm_file_list.json +52 -0
- frequenz_dispatch-1.0.4/src/frequenz_dispatch.egg-info/scm_version.json +8 -0
- frequenz_dispatch-1.0.2/PKG-INFO +0 -136
- frequenz_dispatch-1.0.2/README.md +0 -66
- frequenz_dispatch-1.0.2/RELEASE_NOTES.md +0 -5
- frequenz_dispatch-1.0.2/src/frequenz_dispatch.egg-info/PKG-INFO +0 -136
- frequenz_dispatch-1.0.2/src/frequenz_dispatch.egg-info/requires.txt +0 -54
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/LICENSE +0 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/MANIFEST.in +0 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/setup.cfg +0 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/conftest.py +0 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/py.typed +0 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz_dispatch.egg-info/dependency_links.txt +0 -0
- {frequenz_dispatch-1.0.2 → frequenz_dispatch-1.0.4}/src/frequenz_dispatch.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: frequenz-dispatch
|
|
3
|
+
Version: 1.0.4
|
|
4
|
+
Summary: A highlevel interface for the dispatch API
|
|
5
|
+
Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Documentation, https://frequenz-floss.github.io/frequenz-dispatch-python/
|
|
8
|
+
Project-URL: Changelog, https://github.com/frequenz-floss/frequenz-dispatch-python/releases
|
|
9
|
+
Project-URL: Issues, https://github.com/frequenz-floss/frequenz-dispatch-python/issues
|
|
10
|
+
Project-URL: Repository, https://github.com/frequenz-floss/frequenz-dispatch-python
|
|
11
|
+
Project-URL: Support, https://github.com/frequenz-floss/frequenz-dispatch-python/discussions/categories/support
|
|
12
|
+
Keywords: frequenz,python,actor,frequenz-dispatch,dispatch,highlevel,api
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: <4,>=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: typing-extensions<5.0.0,>=4.13.0
|
|
23
|
+
Requires-Dist: frequenz-sdk<1.0.0-rc2300,>=1.0.0-rc2100
|
|
24
|
+
Requires-Dist: frequenz-channels<2.0.0,>=1.6.1
|
|
25
|
+
Requires-Dist: frequenz-client-dispatch<2.0.0,>=0.11.3
|
|
26
|
+
Requires-Dist: frequenz-client-base<0.12.0,>=0.11.0
|
|
27
|
+
Requires-Dist: frequenz-client-common<0.4.0,>=0.3.8
|
|
28
|
+
Requires-Dist: frequenz-core<2.0.0,>=1.0.2
|
|
29
|
+
Requires-Dist: grpcio<2.0.0,>=1.80.0
|
|
30
|
+
Provides-Extra: dev-flake8
|
|
31
|
+
Requires-Dist: flake8==7.3.0; extra == "dev-flake8"
|
|
32
|
+
Requires-Dist: flake8-datetimez==26.8.1; extra == "dev-flake8"
|
|
33
|
+
Requires-Dist: flake8-docstrings==1.7.0; extra == "dev-flake8"
|
|
34
|
+
Requires-Dist: flake8-pyproject==1.2.4; extra == "dev-flake8"
|
|
35
|
+
Requires-Dist: pydoclint==0.9.1; extra == "dev-flake8"
|
|
36
|
+
Requires-Dist: pydocstyle==6.3.0; extra == "dev-flake8"
|
|
37
|
+
Provides-Extra: dev-formatting
|
|
38
|
+
Requires-Dist: black==26.5.1; extra == "dev-formatting"
|
|
39
|
+
Requires-Dist: isort==9.0.1; extra == "dev-formatting"
|
|
40
|
+
Provides-Extra: dev-mkdocs
|
|
41
|
+
Requires-Dist: black==26.5.1; extra == "dev-mkdocs"
|
|
42
|
+
Requires-Dist: Markdown==3.10.3; extra == "dev-mkdocs"
|
|
43
|
+
Requires-Dist: mike==2.2.0; extra == "dev-mkdocs"
|
|
44
|
+
Requires-Dist: mkdocs-gen-files==0.6.1; extra == "dev-mkdocs"
|
|
45
|
+
Requires-Dist: mkdocs-literate-nav==0.6.3; extra == "dev-mkdocs"
|
|
46
|
+
Requires-Dist: mkdocs-macros-plugin==1.5.0; extra == "dev-mkdocs"
|
|
47
|
+
Requires-Dist: mkdocs-material==9.7.7; extra == "dev-mkdocs"
|
|
48
|
+
Requires-Dist: mkdocstrings[python]==1.0.6; extra == "dev-mkdocs"
|
|
49
|
+
Requires-Dist: mkdocstrings-python==2.0.8; extra == "dev-mkdocs"
|
|
50
|
+
Requires-Dist: frequenz-repo-config[lib]==0.19.0; extra == "dev-mkdocs"
|
|
51
|
+
Provides-Extra: dev-mypy
|
|
52
|
+
Requires-Dist: mypy==2.3.1; extra == "dev-mypy"
|
|
53
|
+
Requires-Dist: grpc-stubs==1.53.0.6; extra == "dev-mypy"
|
|
54
|
+
Requires-Dist: types-Markdown==3.10.2.20260712; extra == "dev-mypy"
|
|
55
|
+
Requires-Dist: frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-mypy"
|
|
56
|
+
Provides-Extra: dev-noxfile
|
|
57
|
+
Requires-Dist: uv==0.12.13; extra == "dev-noxfile"
|
|
58
|
+
Requires-Dist: nox==2026.8.17; extra == "dev-noxfile"
|
|
59
|
+
Requires-Dist: frequenz-repo-config[lib]==0.19.0; extra == "dev-noxfile"
|
|
60
|
+
Provides-Extra: dev-pylint
|
|
61
|
+
Requires-Dist: pylint==4.0.8; extra == "dev-pylint"
|
|
62
|
+
Requires-Dist: frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-pylint"
|
|
63
|
+
Provides-Extra: dev-pytest
|
|
64
|
+
Requires-Dist: pytest==9.1.1; extra == "dev-pytest"
|
|
65
|
+
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.19.0; extra == "dev-pytest"
|
|
66
|
+
Requires-Dist: pytest-mock==3.15.1; extra == "dev-pytest"
|
|
67
|
+
Requires-Dist: pytest-asyncio==1.4.0; extra == "dev-pytest"
|
|
68
|
+
Requires-Dist: async-solipsism==0.9; extra == "dev-pytest"
|
|
69
|
+
Requires-Dist: time-machine==3.5.1; extra == "dev-pytest"
|
|
70
|
+
Provides-Extra: dev
|
|
71
|
+
Requires-Dist: frequenz-dispatch[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]; extra == "dev"
|
|
72
|
+
Dynamic: license-file
|
|
73
|
+
|
|
74
|
+
# Dispatch Highlevel Interface
|
|
75
|
+
|
|
76
|
+
[](https://github.com/frequenz-floss/frequenz-dispatch-python/actions/workflows/ci.yaml)
|
|
77
|
+
[](https://pypi.org/project/frequenz-dispatch/)
|
|
78
|
+
[](https://frequenz-floss.github.io/frequenz-dispatch-python/)
|
|
79
|
+
|
|
80
|
+
## Introduction
|
|
81
|
+
|
|
82
|
+
The `frequenz-dispatch` library provides a high-level Python interface for
|
|
83
|
+
interacting with the Frequenz Dispatch API. This library enables you to
|
|
84
|
+
manage and monitor dispatch operations in microgrids, including lifecycle
|
|
85
|
+
events and running status changes of dispatch operations.
|
|
86
|
+
|
|
87
|
+
The main entry point is the [`Dispatcher`][dispatcher-class] class, which
|
|
88
|
+
provides methods for receiving dispatch lifecycle events and running status
|
|
89
|
+
updates, allowing you to build reactive applications that respond to dispatch
|
|
90
|
+
state changes.
|
|
91
|
+
|
|
92
|
+
## Supported Platforms
|
|
93
|
+
|
|
94
|
+
The following platforms are officially supported (tested):
|
|
95
|
+
|
|
96
|
+
- **Python:** 3.11, 3.13
|
|
97
|
+
- **Operating System:** Ubuntu Linux 24.04
|
|
98
|
+
- **Architectures:** amd64, arm64
|
|
99
|
+
|
|
100
|
+
## Installation
|
|
101
|
+
|
|
102
|
+
### Using pip
|
|
103
|
+
|
|
104
|
+
You can install the package from PyPI:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
python3 -m pip install frequenz-dispatch
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Using pyproject.toml
|
|
111
|
+
|
|
112
|
+
Add the dependency to your `pyproject.toml` file:
|
|
113
|
+
|
|
114
|
+
```toml
|
|
115
|
+
[project]
|
|
116
|
+
dependencies = [
|
|
117
|
+
"frequenz-dispatch >= 1.0.1, < 2",
|
|
118
|
+
]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
> [!NOTE]
|
|
122
|
+
> We recommend pinning the dependency to the latest version for programs,
|
|
123
|
+
> like `"frequenz-dispatch == 1.0.1"`, and specifying a version range
|
|
124
|
+
> spanning one major version for libraries, like
|
|
125
|
+
> `"frequenz-dispatch >= 1.0.1, < 2"`. We follow [semver](https://semver.org/).
|
|
126
|
+
|
|
127
|
+
## Quick Start
|
|
128
|
+
|
|
129
|
+
Here's a minimal example to get you started with lifecycle events:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import asyncio
|
|
133
|
+
import os
|
|
134
|
+
|
|
135
|
+
from frequenz.dispatch import Created, Deleted, Dispatcher, Updated
|
|
136
|
+
|
|
137
|
+
async def main() -> None:
|
|
138
|
+
url = os.getenv("DISPATCH_API_URL", "grpc://localhost:50051")
|
|
139
|
+
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "my-api-key")
|
|
140
|
+
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
|
|
141
|
+
microgrid_id = 1
|
|
142
|
+
|
|
143
|
+
async with Dispatcher(
|
|
144
|
+
microgrid_id=microgrid_id,
|
|
145
|
+
server_url=url,
|
|
146
|
+
auth_key=auth_key,
|
|
147
|
+
sign_secret=sign_secret,
|
|
148
|
+
) as dispatcher:
|
|
149
|
+
events_receiver = dispatcher.new_lifecycle_events_receiver("MY_TYPE")
|
|
150
|
+
|
|
151
|
+
async for event in events_receiver:
|
|
152
|
+
match event:
|
|
153
|
+
case Created(dispatch):
|
|
154
|
+
print(f"Created: {dispatch}")
|
|
155
|
+
case Updated(dispatch):
|
|
156
|
+
print(f"Updated: {dispatch}")
|
|
157
|
+
case Deleted(dispatch):
|
|
158
|
+
print(f"Deleted: {dispatch}")
|
|
159
|
+
|
|
160
|
+
asyncio.run(main())
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The [`Dispatcher` class][dispatcher-class] provides two receiver methods:
|
|
164
|
+
|
|
165
|
+
* [`new_lifecycle_events_receiver()`][lifecycle-events]: Returns a receiver
|
|
166
|
+
that sends a message whenever a Dispatch is created, updated or deleted.
|
|
167
|
+
* [`new_running_state_event_receiver()`][running-status-change]: Returns a
|
|
168
|
+
receiver that sends a dispatch message whenever a dispatch is ready to be
|
|
169
|
+
executed according to the schedule or the running status of the dispatch
|
|
170
|
+
changed in a way that could potentially require the actor to start, stop or
|
|
171
|
+
reconfigure itself.
|
|
172
|
+
|
|
173
|
+
### Example managing actors with dispatch events
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
import os
|
|
177
|
+
from datetime import timedelta
|
|
178
|
+
from unittest.mock import MagicMock
|
|
179
|
+
|
|
180
|
+
from frequenz.channels import Receiver
|
|
181
|
+
from frequenz.sdk.actor import Actor
|
|
182
|
+
|
|
183
|
+
from frequenz.dispatch import Dispatcher, DispatchInfo, MergeByType
|
|
184
|
+
|
|
185
|
+
async def create_actor(
|
|
186
|
+
dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
|
|
187
|
+
) -> Actor:
|
|
188
|
+
return MagicMock(dispatch=dispatch, receiver=receiver)
|
|
189
|
+
|
|
190
|
+
async def run() -> None:
|
|
191
|
+
url = os.getenv(
|
|
192
|
+
"DISPATCH_API_URL", "grpc://dispatch.api.example.com:50051"
|
|
193
|
+
)
|
|
194
|
+
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "my-api-key")
|
|
195
|
+
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
|
|
196
|
+
|
|
197
|
+
microgrid_id = 1
|
|
198
|
+
|
|
199
|
+
async with Dispatcher(
|
|
200
|
+
microgrid_id=microgrid_id,
|
|
201
|
+
server_url=url,
|
|
202
|
+
auth_key=auth_key,
|
|
203
|
+
sign_secret=sign_secret,
|
|
204
|
+
) as dispatcher:
|
|
205
|
+
await dispatcher.start_managing(
|
|
206
|
+
dispatch_type="EXAMPLE_TYPE",
|
|
207
|
+
actor_factory=create_actor,
|
|
208
|
+
merge_strategy=MergeByType(),
|
|
209
|
+
retry_interval=timedelta(seconds=10)
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
await dispatcher
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Documentation
|
|
216
|
+
|
|
217
|
+
For complete API documentation, examples, and advanced usage patterns, see
|
|
218
|
+
[the documentation][docs].
|
|
219
|
+
|
|
220
|
+
[dispatcher-class]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher
|
|
221
|
+
[lifecycle-events]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.new_lifecycle_events_receiver
|
|
222
|
+
[running-status-change]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.Dispatcher.new_running_state_event_receiver
|
|
223
|
+
[docs]: https://frequenz-floss.github.io/frequenz-dispatch-python/latest/
|
|
224
|
+
|
|
225
|
+
## Contributing
|
|
226
|
+
|
|
227
|
+
If you want to know how to build this project and contribute to it, please
|
|
228
|
+
check out the [Contributing Guide](CONTRIBUTING.md).
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Dispatch Highlevel Interface
|
|
2
|
+
|
|
3
|
+
[](https://github.com/frequenz-floss/frequenz-dispatch-python/actions/workflows/ci.yaml)
|
|
4
|
+
[](https://pypi.org/project/frequenz-dispatch/)
|
|
5
|
+
[](https://frequenz-floss.github.io/frequenz-dispatch-python/)
|
|
6
|
+
|
|
7
|
+
## Introduction
|
|
8
|
+
|
|
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.
|
|
13
|
+
|
|
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.
|
|
18
|
+
|
|
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
|
|
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 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
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import os
|
|
104
|
+
from datetime import timedelta
|
|
105
|
+
from unittest.mock import MagicMock
|
|
106
|
+
|
|
107
|
+
from frequenz.channels import Receiver
|
|
108
|
+
from frequenz.sdk.actor import Actor
|
|
109
|
+
|
|
110
|
+
from frequenz.dispatch import Dispatcher, DispatchInfo, MergeByType
|
|
111
|
+
|
|
112
|
+
async def create_actor(
|
|
113
|
+
dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
|
|
114
|
+
) -> Actor:
|
|
115
|
+
return MagicMock(dispatch=dispatch, receiver=receiver)
|
|
116
|
+
|
|
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")
|
|
122
|
+
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
|
|
123
|
+
|
|
124
|
+
microgrid_id = 1
|
|
125
|
+
|
|
126
|
+
async with Dispatcher(
|
|
127
|
+
microgrid_id=microgrid_id,
|
|
128
|
+
server_url=url,
|
|
129
|
+
auth_key=auth_key,
|
|
130
|
+
sign_secret=sign_secret,
|
|
131
|
+
) as dispatcher:
|
|
132
|
+
await dispatcher.start_managing(
|
|
133
|
+
dispatch_type="EXAMPLE_TYPE",
|
|
134
|
+
actor_factory=create_actor,
|
|
135
|
+
merge_strategy=MergeByType(),
|
|
136
|
+
retry_interval=timedelta(seconds=10)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
await dispatcher
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Documentation
|
|
143
|
+
|
|
144
|
+
For complete API documentation, examples, and advanced usage patterns, see
|
|
145
|
+
[the documentation][docs].
|
|
146
|
+
|
|
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/
|
|
151
|
+
|
|
152
|
+
## Contributing
|
|
153
|
+
|
|
154
|
+
If you want to know how to build this project and contribute to it, please
|
|
155
|
+
check out the [Contributing Guide](CONTRIBUTING.md).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Dispatch Highlevel Interface Release Notes
|
|
2
|
+
|
|
3
|
+
## Enhancements
|
|
4
|
+
|
|
5
|
+
- Improved docstring documentation across the project.
|
|
6
|
+
|
|
7
|
+
## Bug Fixes
|
|
8
|
+
|
|
9
|
+
* Fixed documentation cross-references to dependencies by updating the mkdocstrings inventories to match the minimum dependency versions and adding the missing `frequenz-client-base` inventory.
|
|
10
|
+
* Declared the missing direct dependencies `frequenz-client-common`, `frequenz-core` and `grpcio`, which were previously only pulled in indirectly through `frequenz-client-dispatch`.
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
[build-system]
|
|
5
5
|
requires = [
|
|
6
|
-
"setuptools ==
|
|
7
|
-
"setuptools_scm[toml] ==
|
|
8
|
-
"frequenz-repo-config[lib] == 0.
|
|
6
|
+
"setuptools == 84.0.0",
|
|
7
|
+
"setuptools_scm[toml] == 10.2.1",
|
|
8
|
+
"frequenz-repo-config[lib] == 0.19.0",
|
|
9
9
|
]
|
|
10
10
|
build-backend = "setuptools.build_meta"
|
|
11
11
|
|
|
@@ -13,7 +13,8 @@ build-backend = "setuptools.build_meta"
|
|
|
13
13
|
name = "frequenz-dispatch"
|
|
14
14
|
description = "A highlevel interface for the dispatch API"
|
|
15
15
|
readme = "README.md"
|
|
16
|
-
license =
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
17
18
|
keywords = [
|
|
18
19
|
"frequenz",
|
|
19
20
|
"python",
|
|
@@ -26,7 +27,6 @@ keywords = [
|
|
|
26
27
|
classifiers = [
|
|
27
28
|
"Development Status :: 3 - Alpha",
|
|
28
29
|
"Intended Audience :: Developers",
|
|
29
|
-
"License :: OSI Approved :: MIT License",
|
|
30
30
|
"Programming Language :: Python :: 3",
|
|
31
31
|
"Programming Language :: Python :: 3 :: Only",
|
|
32
32
|
"Topic :: Software Development :: Libraries",
|
|
@@ -37,11 +37,14 @@ dependencies = [
|
|
|
37
37
|
"typing-extensions >= 4.13.0, < 5.0.0",
|
|
38
38
|
# Make sure to update the version for cross-referencing also in the
|
|
39
39
|
# mkdocs.yml file when changing the version here (look for the config key
|
|
40
|
-
# plugins.mkdocstrings.handlers.python.
|
|
40
|
+
# plugins.mkdocstrings.handlers.python.inventories)
|
|
41
41
|
"frequenz-sdk >= 1.0.0-rc2100, < 1.0.0-rc2300",
|
|
42
42
|
"frequenz-channels >= 1.6.1, < 2.0.0",
|
|
43
43
|
"frequenz-client-dispatch >= 0.11.3, < 2.0.0",
|
|
44
44
|
"frequenz-client-base >= 0.11.0, < 0.12.0",
|
|
45
|
+
"frequenz-client-common >= 0.3.8, < 0.4.0",
|
|
46
|
+
"frequenz-core >= 1.0.2, < 2.0.0",
|
|
47
|
+
"grpcio >= 1.80.0, < 2.0.0",
|
|
45
48
|
]
|
|
46
49
|
dynamic = ["version"]
|
|
47
50
|
|
|
@@ -52,49 +55,50 @@ email = "floss@frequenz.com"
|
|
|
52
55
|
[project.optional-dependencies]
|
|
53
56
|
dev-flake8 = [
|
|
54
57
|
"flake8 == 7.3.0",
|
|
58
|
+
"flake8-datetimez == 26.8.1",
|
|
55
59
|
"flake8-docstrings == 1.7.0",
|
|
56
|
-
"flake8-pyproject == 1.2.
|
|
57
|
-
"pydoclint == 0.
|
|
60
|
+
"flake8-pyproject == 1.2.4", # For reading the flake8 config from pyproject.toml
|
|
61
|
+
"pydoclint == 0.9.1",
|
|
58
62
|
"pydocstyle == 6.3.0",
|
|
59
63
|
]
|
|
60
|
-
dev-formatting = ["black ==
|
|
64
|
+
dev-formatting = ["black == 26.5.1", "isort == 9.0.1"]
|
|
61
65
|
dev-mkdocs = [
|
|
62
|
-
"black ==
|
|
63
|
-
"Markdown==3.10",
|
|
64
|
-
"mike == 2.
|
|
65
|
-
"mkdocs-gen-files == 0.
|
|
66
|
-
"mkdocs-literate-nav == 0.6.
|
|
66
|
+
"black == 26.5.1",
|
|
67
|
+
"Markdown==3.10.3",
|
|
68
|
+
"mike == 2.2.0",
|
|
69
|
+
"mkdocs-gen-files == 0.6.1",
|
|
70
|
+
"mkdocs-literate-nav == 0.6.3",
|
|
67
71
|
"mkdocs-macros-plugin == 1.5.0",
|
|
68
|
-
"mkdocs-material == 9.7.
|
|
69
|
-
"mkdocstrings[python] == 0.
|
|
70
|
-
"mkdocstrings-python ==
|
|
71
|
-
"frequenz-repo-config[lib] == 0.
|
|
72
|
+
"mkdocs-material == 9.7.7",
|
|
73
|
+
"mkdocstrings[python] == 1.0.6",
|
|
74
|
+
"mkdocstrings-python == 2.0.8",
|
|
75
|
+
"frequenz-repo-config[lib] == 0.19.0",
|
|
72
76
|
]
|
|
73
77
|
dev-mypy = [
|
|
74
|
-
"mypy ==
|
|
78
|
+
"mypy == 2.3.1",
|
|
75
79
|
# This dependency introduces breaking changes in patch releases
|
|
76
80
|
"grpc-stubs == 1.53.0.6",
|
|
77
|
-
"types-Markdown == 3.10.
|
|
81
|
+
"types-Markdown == 3.10.2.20260712",
|
|
78
82
|
# For checking the noxfile, docs/ script, and tests
|
|
79
83
|
"frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]",
|
|
80
84
|
]
|
|
81
85
|
dev-noxfile = [
|
|
82
|
-
"uv == 0.
|
|
83
|
-
"nox ==
|
|
84
|
-
"frequenz-repo-config[lib] == 0.
|
|
86
|
+
"uv == 0.12.13",
|
|
87
|
+
"nox == 2026.8.17",
|
|
88
|
+
"frequenz-repo-config[lib] == 0.19.0",
|
|
85
89
|
]
|
|
86
90
|
dev-pylint = [
|
|
87
|
-
"pylint ==
|
|
91
|
+
"pylint == 4.0.8",
|
|
88
92
|
# For checking the noxfile, docs/ script, and tests
|
|
89
93
|
"frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]",
|
|
90
94
|
]
|
|
91
95
|
dev-pytest = [
|
|
92
|
-
"pytest ==
|
|
93
|
-
"frequenz-repo-config[extra-lint-examples] == 0.
|
|
96
|
+
"pytest == 9.1.1",
|
|
97
|
+
"frequenz-repo-config[extra-lint-examples] == 0.19.0",
|
|
94
98
|
"pytest-mock == 3.15.1",
|
|
95
|
-
"pytest-asyncio == 1.
|
|
96
|
-
"async-solipsism == 0.
|
|
97
|
-
"time-machine ==
|
|
99
|
+
"pytest-asyncio == 1.4.0",
|
|
100
|
+
"async-solipsism == 0.9",
|
|
101
|
+
"time-machine == 3.5.1",
|
|
98
102
|
]
|
|
99
103
|
dev = [
|
|
100
104
|
"frequenz-dispatch[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
|
|
@@ -133,6 +137,9 @@ check-yield-types = false
|
|
|
133
137
|
arg-type-hints-in-docstring = false
|
|
134
138
|
arg-type-hints-in-signature = true
|
|
135
139
|
allow-init-docstring = true
|
|
140
|
+
check-class-attributes = true
|
|
141
|
+
check-style-mismatch = true
|
|
142
|
+
require-inline-class-var-docs = true
|
|
136
143
|
|
|
137
144
|
[tool.pylint.similarities]
|
|
138
145
|
ignore-comments = ['yes']
|
|
@@ -169,13 +176,15 @@ disable = [
|
|
|
169
176
|
# coming for external dependencies that are hard to address here, once this is
|
|
170
177
|
# fixed, we can add the following options:
|
|
171
178
|
# -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning
|
|
172
|
-
addopts = "-W=all
|
|
179
|
+
addopts = "-W=all"
|
|
173
180
|
testpaths = ["tests", "src"]
|
|
181
|
+
asyncio_debug = true
|
|
174
182
|
asyncio_mode = "auto"
|
|
175
183
|
asyncio_default_fixture_loop_scope = "function"
|
|
176
184
|
required_plugins = ["pytest-asyncio", "pytest-mock"]
|
|
177
185
|
|
|
178
186
|
[tool.mypy]
|
|
187
|
+
enable_error_code = ["exhaustive-match"]
|
|
179
188
|
explicit_package_bases = true
|
|
180
189
|
namespace_packages = true
|
|
181
190
|
# This option disables mypy cache, and it is sometimes useful to enable it if
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# License: MIT
|
|
2
2
|
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
|
|
3
3
|
|
|
4
|
-
"""A
|
|
4
|
+
"""A high-level interface for the dispatch API.
|
|
5
5
|
|
|
6
6
|
A small overview of the most important classes in this module:
|
|
7
7
|
|
|
8
|
-
* [Dispatcher][
|
|
9
|
-
* [Dispatch][
|
|
10
|
-
* [ActorDispatcher][
|
|
8
|
+
* [`Dispatcher`][.Dispatcher]: The entry point for the API.
|
|
9
|
+
* [`Dispatch`][.Dispatch]: A dispatch type with lots of useful extra functionality.
|
|
10
|
+
* [`ActorDispatcher`][.ActorDispatcher]: A service to manage other actors based on
|
|
11
11
|
incoming dispatches.
|
|
12
|
-
* [Created][
|
|
13
|
-
[Updated][
|
|
14
|
-
[Deleted][
|
|
12
|
+
* [`Created`][.Created],
|
|
13
|
+
[`Updated`][.Updated],
|
|
14
|
+
[`Deleted`][.Deleted]: Dispatch event types.
|
|
15
15
|
|
|
16
16
|
"""
|
|
17
17
|
|