Index
frequenz.client.dispatch ¤
Dispatch API client for Python.
Classes¤
frequenz.client.dispatch.Client ¤
Bases: BaseApiClient[MicrogridDispatchServiceStub]
Dispatch API client.
Source code in frequenz/client/dispatch/_client.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
Attributes¤
channel
property
¤
channel: Channel
The underlying gRPC channel used to communicate with the server.
Warning
This channel is provided as a last resort for advanced users. It is not recommended to use this property directly unless you know what you are doing and you don't care about being tied to a specific gRPC library.
RAISES | DESCRIPTION |
---|---|
ClientNotConnected
|
If the client is not connected to the server. |
channel_defaults
property
¤
The default options for the gRPC channel.
streams
class-attribute
instance-attribute
¤
streams: dict[
int,
GrpcStreamBroadcaster[
StreamMicrogridDispatchesResponse, DispatchEvent
],
] = {}
A dictionary of streamers, keyed by microgrid_id.
stub
property
¤
The underlying gRPC stub.
Warning
This stub is provided as a last resort for advanced users. It is not recommended to use this property directly unless you know what you are doing and you don't care about being tied to a specific gRPC library.
RAISES | DESCRIPTION |
---|---|
ClientNotConnected
|
If the client is not connected to the server. |
Functions¤
__aexit__
async
¤
__aexit__(
_exc_type: type[BaseException] | None,
_exc_val: BaseException | None,
_exc_tb: Any | None,
) -> bool | None
Exit a context manager.
Source code in frequenz/client/base/client.py
__init__ ¤
Initialize the client.
PARAMETER | DESCRIPTION |
---|---|
server_url |
The URL of the server to connect to.
TYPE:
|
key |
API key to use for authentication.
TYPE:
|
connect |
Whether to connect to the service immediately.
TYPE:
|
Source code in frequenz/client/dispatch/_client.py
connect ¤
connect(server_url: str | None = None) -> None
Connect to the server, possibly using a new URL.
If the client is already connected and the URL is the same as the previous URL, this method does nothing. If you want to force a reconnection, you can call disconnect() first.
PARAMETER | DESCRIPTION |
---|---|
server_url |
The URL of the server to connect to. If not provided, the previously used URL is used.
TYPE:
|
Source code in frequenz/client/base/client.py
create
async
¤
create(
microgrid_id: int,
type: str,
start_time: datetime,
duration: timedelta,
selector: ComponentSelector,
active: bool = True,
dry_run: bool = False,
payload: dict[str, Any] | None = None,
recurrence: RecurrenceRule | None = None,
) -> Dispatch
Create a dispatch.
Will try to return the created dispatch, identifying it by the same fields as the request.
PARAMETER | DESCRIPTION |
---|---|
microgrid_id |
The microgrid_id to create the dispatch for.
TYPE:
|
type |
User defined string to identify the dispatch type.
TYPE:
|
start_time |
The start time of the dispatch.
TYPE:
|
duration |
The duration of the dispatch.
TYPE:
|
selector |
The component selector for the dispatch.
TYPE:
|
active |
The active status of the dispatch.
TYPE:
|
dry_run |
The dry_run status of the dispatch.
TYPE:
|
payload |
The payload of the dispatch. |
recurrence |
The recurrence rule of the dispatch.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dispatch
|
The created dispatch
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If start_time is in the past. |
ValueError
|
If the created dispatch could not be found. |
Source code in frequenz/client/dispatch/_client.py
delete
async
¤
Delete a dispatch.
PARAMETER | DESCRIPTION |
---|---|
microgrid_id |
The microgrid_id to delete the dispatch for.
TYPE:
|
dispatch_id |
The dispatch_id to delete.
TYPE:
|
Source code in frequenz/client/dispatch/_client.py
disconnect
async
¤
Disconnect from the server.
If the client is not connected, this method does nothing.
get
async
¤
Get a dispatch.
PARAMETER | DESCRIPTION |
---|---|
microgrid_id |
The microgrid_id to get the dispatch for.
TYPE:
|
dispatch_id |
The dispatch_id to get.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dispatch
|
The dispatch.
TYPE:
|
Source code in frequenz/client/dispatch/_client.py
list
async
¤
list(
microgrid_id: int,
component_selectors: Iterator[ComponentSelector] = iter(
()
),
start_from: datetime | None = None,
start_to: datetime | None = None,
end_from: datetime | None = None,
end_to: datetime | None = None,
active: bool | None = None,
dry_run: bool | None = None,
page_size: int | None = None,
) -> AsyncIterator[Iterator[Dispatch]]
List dispatches.
This function handles pagination internally and returns an async iterator
over the dispatches. Pagination parameters like page_size
and page_token
can be used, but they are mutually exclusive.
Example usage:
client = Client(key="key", server_url="grpc://fz-0004.frequenz.io")
async for page in client.list(microgrid_id=1):
for dispatch in page:
print(dispatch)
PARAMETER | DESCRIPTION |
---|---|
microgrid_id |
The microgrid_id to list dispatches for.
TYPE:
|
component_selectors |
optional, list of component ids or categories to filter by.
TYPE:
|
start_from |
optional, filter by start_time >= start_from.
TYPE:
|
start_to |
optional, filter by start_time < start_to.
TYPE:
|
end_from |
optional, filter by end_time >= end_from.
TYPE:
|
end_to |
optional, filter by end_time < end_to.
TYPE:
|
active |
optional, filter by active status.
TYPE:
|
dry_run |
optional, filter by dry_run status.
TYPE:
|
page_size |
optional, number of dispatches to return per page.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AsyncIterator[Iterator[Dispatch]]
|
An async iterator over pages of dispatches. |
YIELDS | DESCRIPTION |
---|---|
AsyncIterator[Iterator[Dispatch]]
|
A page of dispatches over which you can lazily iterate. |
Source code in frequenz/client/dispatch/_client.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
stream ¤
stream(microgrid_id: int) -> Receiver[DispatchEvent]
Receive a stream of dispatch events.
This function returns a receiver channel that can be used to receive dispatch events. An event is one of [CREATE, UPDATE, DELETE].
Example usage:
client = Client(key="key", server_url="grpc://fz-0004.frequenz.io")
async for message in client.stream(microgrid_id=1):
print(message.event, message.dispatch)
PARAMETER | DESCRIPTION |
---|---|
microgrid_id |
The microgrid_id to receive dispatches for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Receiver[DispatchEvent]
|
A receiver channel to receive the stream of dispatch events. |
Source code in frequenz/client/dispatch/_client.py
update
async
¤
Update a dispatch.
The new_fields
argument is a dictionary of fields to update. The keys are
the field names, and the values are the new values for the fields.
For recurrence fields, the keys are preceeded by "recurrence.".
Note that updating type
and dry_run
is not supported.
PARAMETER | DESCRIPTION |
---|---|
microgrid_id |
The microgrid_id to update the dispatch for.
TYPE:
|
dispatch_id |
The dispatch_id to update.
TYPE:
|
new_fields |
The fields to update. |
RETURNS | DESCRIPTION |
---|---|
Dispatch
|
The updated dispatch.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If updating |
Source code in frequenz/client/dispatch/_client.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|