Index
frequenz.client.marketmetering ¤
Market Metering API client for Python.
This package provides a Python client for the Frequenz Market Metering API, which allows streaming historical and real-time metering samples from Market Locations.
Example
from datetime import datetime, timezone
from frequenz.client.marketmetering import MarketMeteringApiClient
from frequenz.client.marketmetering.types import (
EnergyFlowDirection,
MarketArea,
MarketLocationId,
MarketLocationIdType,
MarketLocationRef,
MetricType,
)
client = MarketMeteringApiClient(
server_url="grpc://marketmetering.example.com",
auth_key="your-api-key",
sign_secret="your-sign-secret",
)
market_location = MarketLocationRef(
market_area=MarketArea.EU_DE,
market_location_id=MarketLocationId(
value="DE01234567890",
type=MarketLocationIdType.MALO_ID,
),
)
async for series in client.stream_samples(
market_locations=[market_location],
directions=[EnergyFlowDirection.IMPORT],
metric_types=[MetricType.ACTIVE_ENERGY],
start_time=datetime(2025, 1, 1, tzinfo=timezone.utc),
):
for sample in series.samples:
print(f"{sample.sample_time}: {sample.value}")
Classes¤
frequenz.client.marketmetering.ActivationFilter ¤
Bases: Enum
Filter for Market Location activation status.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
ALL
class-attribute
instance-attribute
¤
Return all Market Locations regardless of activation status.
ONLY_ACTIVE
class-attribute
instance-attribute
¤
Return only active Market Locations.
ONLY_INACTIVE
class-attribute
instance-attribute
¤
Return only inactive Market Locations.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified filter (defaults to ONLY_ACTIVE).
frequenz.client.marketmetering.DataQuality ¤
Bases: Enum
Classification of data quality for a metering sample.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
CORRECTED
class-attribute
instance-attribute
¤
Value that was initially delivered but later amended.
ESTIMATED
class-attribute
instance-attribute
¤
Value inferred or interpolated due to missing or invalid readings.
MEASURED
class-attribute
instance-attribute
¤
Raw value directly received from the metering system.
MISSING
class-attribute
instance-attribute
¤
No valid value is available for this interval.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified quality.
Methods:¤
frequenz.client.marketmetering.DownsamplingMethod ¤
Bases: Enum
Defines how multiple native samples are combined when downsampling.
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.EnergyFlowDirection ¤
Bases: Enum
Direction of energy flow for metering samples.
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketArea ¤
Bases: Enum
Market area enum representing the jurisdiction.
Market areas are organized by geographical region: - EU_: Europe - NA_: North America - AP_: Asia-Pacific - OC_: Oceania - EURASIA_*: Eurasia
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
EURASIA_RU
class-attribute
instance-attribute
¤
Russia.
EU_DE
class-attribute
instance-attribute
¤
Germany (Marktlokation / MaLo).
EU_NL
class-attribute
instance-attribute
¤
Netherlands (EAN).
EU_NORDICS
class-attribute
instance-attribute
¤
Nordic countries (Denmark, Finland, Norway, Sweden).
EU_UK
class-attribute
instance-attribute
¤
United Kingdom (MPAN).
NA_US_CAISO
class-attribute
instance-attribute
¤
US - California ISO.
NA_US_ERCOT
class-attribute
instance-attribute
¤
US - ERCOT region (ESI ID).
NA_US_ISONE
class-attribute
instance-attribute
¤
US - ISO New England.
NA_US_PJM
class-attribute
instance-attribute
¤
US - PJM Interconnection.
OC_AU
class-attribute
instance-attribute
¤
Australia (NMI).
OC_NZ
class-attribute
instance-attribute
¤
New Zealand (ICP).
OTHER
class-attribute
instance-attribute
¤
Other or not yet modelled areas.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified market area.
frequenz.client.marketmetering.MarketLocation
dataclass
¤
A Market Location with its configuration.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
supported_directions
instance-attribute
¤
supported_directions: list[EnergyFlowDirection]
Supported energy flow directions.
time_resolution
instance-attribute
¤
time_resolution: TimeResolution
Time resolution of the metering data.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: MarketLocationMetadata) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocation instance. |
Source code in src/frequenz/client/marketmetering/types.py
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationMetadata
|
The protobuf representation. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationChangedField ¤
Bases: Enum
Fields that can be tracked for changes in Market Location history.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
IS_ACTIVE
class-attribute
instance-attribute
¤
Activity status of the Market Location.
SUPPORTED_DIRECTIONS
class-attribute
instance-attribute
¤
Supported energy flow directions.
TIME_RESOLUTION
class-attribute
instance-attribute
¤
Time resolution of the metering data.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified field.
frequenz.client.marketmetering.MarketLocationDetail
dataclass
¤
A Market Location with server-managed metadata.
This includes the core MarketLocation configuration plus
server-assigned fields such as revision, activation status,
and timestamps.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
create_time
instance-attribute
¤
create_time: datetime
Timestamp when the Market Location was created.
last_deactivated_time
instance-attribute
¤
last_deactivated_time: datetime | None
Timestamp when the Market Location was last deactivated, if ever.
market_location
instance-attribute
¤
market_location: MarketLocation
The core Market Location configuration.
market_location_ref
instance-attribute
¤
market_location_ref: MarketLocationRef
Reference to this Market Location.
revision
instance-attribute
¤
revision: int
Server-managed revision number (monotonically increasing).
update_time
instance-attribute
¤
update_time: datetime
Timestamp of the last update to this Market Location.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: MarketLocationDetail) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationDetail instance. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationEntry
dataclass
¤
A Market Location entry as returned by list operations.
Wraps a MarketLocationDetail together with the owning enterprise ID.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
market_location
property
¤
market_location: MarketLocation
The core Market Location configuration (convenience accessor).
market_location_detail
instance-attribute
¤
market_location_detail: MarketLocationDetail
Full Market Location details including metadata.
market_location_ref
property
¤
market_location_ref: MarketLocationRef
Reference to this Market Location.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: MarketLocationDetail) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationEntry instance. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationId
dataclass
¤
Market-standard identifier describing a Market Location.
A Market Location is a jurisdiction-specific point of metering used for regulatory processes such as settlement, billing, supplier switching, etc.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: MarketLocationId) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationId instance. |
Source code in src/frequenz/client/marketmetering/types.py
to_id_value_protobuf ¤
Convert to a MarketLocationIdValue protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationIdValue
|
The protobuf representation containing only the value. |
Source code in src/frequenz/client/marketmetering/types.py
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationId
|
The protobuf representation. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationIdType ¤
Bases: Enum
Type of external market identifier.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
CUPS
class-attribute
instance-attribute
¤
Spain – Código Unificado de Punto de Suministro.
EAN
class-attribute
instance-attribute
¤
European Article Number (used in Netherlands, Belgium, etc.).
ESI_ID
class-attribute
instance-attribute
¤
United States – Electric Service Identifier (ESI ID).
GSRN
class-attribute
instance-attribute
¤
Nordic countries – GS1 Global Service Relation Number.
ICP
class-attribute
instance-attribute
¤
New Zealand – Installation Control Point.
MALO_ID
class-attribute
instance-attribute
¤
Germany – Marktlokations-ID (MaLo-ID).
MPAN
class-attribute
instance-attribute
¤
United Kingdom – Meter Point Administration Number.
NMI
class-attribute
instance-attribute
¤
Australia – National Metering Identifier.
OTHER
class-attribute
instance-attribute
¤
Generic meter identifier for markets not modeled explicitly.
POD
class-attribute
instance-attribute
¤
Italy – Punto di Prelievo (Point of Delivery).
PRM
class-attribute
instance-attribute
¤
France – Point de Référence et Mesure (PRM).
SPN
class-attribute
instance-attribute
¤
Japan – Supply Point Number.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified identifier type.
ZAEHLPUNKT
class-attribute
instance-attribute
¤
Austria – Zählpunktbezeichnung.
frequenz.client.marketmetering.MarketLocationOperationError
dataclass
¤
Structured error for a rejected Market Location operation.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
code
instance-attribute
¤
Machine-readable classification of the failure.
message
instance-attribute
¤
message: str
Human-readable diagnostic message for logging and debugging.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: MarketLocationOperationError) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationOperationError instance. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationOperationErrorCode ¤
Bases: Enum
Error codes for Market Location activate/deactivate operations.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
ALREADY_IN_TARGET_STATE
class-attribute
instance-attribute
¤
The Market Location is already in the requested state.
ENTERPRISE_MISMATCH
class-attribute
instance-attribute
¤
The enterprise ID does not match the Market Location's owner.
NOT_FOUND
class-attribute
instance-attribute
¤
The Market Location was not found.
OPERATION_REJECTED
class-attribute
instance-attribute
¤
The operation was rejected by the server.
PERMISSION_DENIED
class-attribute
instance-attribute
¤
The caller does not have permission for this operation.
UNKNOWN_ERROR
class-attribute
instance-attribute
¤
Unknown error.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified error.
frequenz.client.marketmetering.MarketLocationOperationResult
dataclass
¤
Result of an activate or deactivate operation on a Market Location.
If error is None the operation succeeded; otherwise it was rejected.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
error
instance-attribute
¤
error: MarketLocationOperationError | None
Error details if the operation was rejected, None on success.
market_location_ref
instance-attribute
¤
market_location_ref: MarketLocationRef
Reference to the Market Location.
revision
instance-attribute
¤
revision: int
Server-managed revision after the operation. Populated only on success.
update_time
instance-attribute
¤
update_time: datetime | None
Timestamp of the operation. Populated only on success.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(
pb_obj: MarketLocationOperationResult,
) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationOperationResult instance. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationRef
dataclass
¤
Reference to a Market Location within a market area.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
enterprise_id
class-attribute
instance-attribute
¤
Owning enterprise ID, when returned by the service.
market_area
instance-attribute
¤
market_area: MarketArea
Regulatory jurisdiction in which this Market Location is registered.
market_location_id
instance-attribute
¤
market_location_id: MarketLocationId
Market-wide identifier (MaLo, MPAN, ESI-ID, NMI, ...).
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: MarketLocationRef) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationRef instance. |
Source code in src/frequenz/client/marketmetering/types.py
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationRef
|
The enterprise-less protobuf selector used in requests. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationSample
dataclass
¤
A metering sample with metadata.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
resampling_method
instance-attribute
¤
resampling_method: ResamplingMethod
How this sample was produced.
update_time
instance-attribute
¤
update_time: datetime | None
Timestamp when the sample was last updated.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(
pb_obj: (
MarketLocationSample | MarketLocationSampleDetail
),
) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message (simple or detailed).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationSample instance. |
Source code in src/frequenz/client/marketmetering/types.py
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationSample
|
The protobuf representation. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationSeries
dataclass
¤
A time series for a single logical Market Location.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
market_location_ref
instance-attribute
¤
market_location_ref: MarketLocationRef
Reference to the Market Location.
metric_unit
instance-attribute
¤
metric_unit: MetricUnit
Physical unit in which the metric is expressed.
resolution
instance-attribute
¤
resolution: TimeResolution
Market Location's current contractual resolution.
samples
instance-attribute
¤
samples: list[MarketLocationSample]
Ordered samples representing this time series.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: MarketLocationSeries) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new MarketLocationSeries instance. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationUpdate
dataclass
¤
Fields to update in a Market Location.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
payload
class-attribute
instance-attribute
¤
New payload (replaces existing payload).
supported_directions
class-attribute
instance-attribute
¤
supported_directions: list[EnergyFlowDirection] | None = (
None
)
New supported directions.
time_resolution
class-attribute
instance-attribute
¤
time_resolution: TimeResolution | None = None
New time resolution.
Methods:¤
to_protobuf ¤
to_protobuf() -> tuple[MarketLocationUpdate, FieldMask]
Convert to protobuf message and field mask.
| RETURNS | DESCRIPTION |
|---|---|
tuple[MarketLocationUpdate, FieldMask]
|
A tuple containing the update message and the field mask. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketLocationsFilter
dataclass
¤
Filter criteria for listing Market Locations.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
activation_filter
class-attribute
instance-attribute
¤
activation_filter: ActivationFilter = (
ActivationFilter.ONLY_ACTIVE
)
Filter by activation status (defaults to only active locations).
market_location_id_filters
class-attribute
instance-attribute
¤
market_location_id_filters: Iterable[MarketLocationId] = (
field(default_factory=list)
)
Filter by specific Market Location IDs.
Methods:¤
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationsFilter
|
The protobuf representation. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.MarketMeteringApiClient ¤
Bases: BaseApiClient[MarketMeteringServiceStub]
Market Metering API client.
This client provides access to the Market Metering Service, allowing you to stream historical and real-time metering samples from Market Locations.
Example
from datetime import datetime, timezone
from frequenz.client.marketmetering import MarketMeteringApiClient
from frequenz.client.marketmetering.types import (
EnergyFlowDirection,
MarketArea,
MarketLocationId,
MarketLocationIdType,
MarketLocationRef,
MetricType,
)
client = MarketMeteringApiClient(
server_url="grpc://marketmetering.example.com",
auth_key="your-api-key",
sign_secret="your-sign-secret",
)
market_location = MarketLocationRef(
market_area=MarketArea.EU_DE,
market_location_id=MarketLocationId(
value="DE01234567890",
type=MarketLocationIdType.MALO_ID,
),
)
async for series in client.stream_samples(
market_locations=[market_location],
directions=[EnergyFlowDirection.IMPORT],
metric_types=[MetricType.ACTIVE_ENERGY],
start_time=datetime(2025, 1, 1, tzinfo=timezone.utc),
):
for sample in series.samples:
print(f"{sample.sample_time}: {sample.value} {series.metric_unit.name}")
Source code in src/frequenz/client/marketmetering/_client.py
48 49 50 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 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
Attributes¤
channel
property
¤
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.
Methods:¤
__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__ ¤
__init__(
*,
server_url: str,
auth_key: str,
sign_secret: str | None = None,
connect: bool = True,
call_timeout: timedelta = timedelta(seconds=60),
stream_timeout: timedelta = timedelta(minutes=5)
) -> None
Initialize the client.
| PARAMETER | DESCRIPTION |
|---|---|
server_url
|
The URL of the server to connect to.
TYPE:
|
auth_key
|
API key to use for authentication.
TYPE:
|
sign_secret
|
Optional secret for signing requests.
TYPE:
|
connect
|
Whether to connect to the service immediately.
TYPE:
|
call_timeout
|
Timeout for gRPC calls, default is 60 seconds. |
stream_timeout
|
Timeout for gRPC streams, default is 5 minutes. |
Source code in src/frequenz/client/marketmetering/_client.py
activate_market_locations
async
¤
activate_market_locations(
*, market_location_refs: list[MarketLocationRef]
) -> list[MarketLocationOperationResult]
Activate one or more Market Locations.
| PARAMETER | DESCRIPTION |
|---|---|
market_location_refs
|
References to the locations to activate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[MarketLocationOperationResult]
|
A list of operation results, one per requested location. |
Source code in src/frequenz/client/marketmetering/_client.py
connect ¤
connect(
server_url: str | None = None,
*,
auth_key: str | None | EllipsisType = ...,
sign_secret: str | None | EllipsisType = ...
) -> 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:
|
auth_key
|
The API key to use when connecting to the service. If an Ellipsis is provided, the previously used auth_key is used.
TYPE:
|
sign_secret
|
The secret to use when creating message HMAC. If an Ellipsis is provided,
TYPE:
|
Source code in frequenz/client/base/client.py
create_market_location
async
¤
create_market_location(
*,
market_location_ref: MarketLocationRef,
market_location: MarketLocation
) -> MarketLocationDetail
Create a new Market Location.
| PARAMETER | DESCRIPTION |
|---|---|
market_location_ref
|
The reference ID for the new location.
TYPE:
|
market_location
|
The configuration of the new location.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationDetail
|
The created Market Location with server-assigned metadata. |
Source code in src/frequenz/client/marketmetering/_client.py
deactivate_market_locations
async
¤
deactivate_market_locations(
*, market_location_refs: list[MarketLocationRef]
) -> list[MarketLocationOperationResult]
Deactivate one or more Market Locations.
| PARAMETER | DESCRIPTION |
|---|---|
market_location_refs
|
References to the locations to deactivate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[MarketLocationOperationResult]
|
A list of operation results, one per requested location. |
Source code in src/frequenz/client/marketmetering/_client.py
disconnect
async
¤
Disconnect from the server.
If the client is not connected, this method does nothing.
list_market_locations
async
¤
list_market_locations(
*,
filters: MarketLocationsFilter | None = None,
revision_selection: RevisionSelection | None = None,
pagination_params: PaginationParams | None = None
) -> tuple[
list[MarketLocationEntry], PaginationParams | None
]
List Market Locations.
| PARAMETER | DESCRIPTION |
|---|---|
filters
|
Optional filters for the query.
TYPE:
|
revision_selection
|
Optional revision selection criteria.
TYPE:
|
pagination_params
|
Optional pagination parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[MarketLocationEntry]
|
A tuple containing a list of Market Location entries and optional |
PaginationParams | None
|
pagination parameters for the next page. |
Source code in src/frequenz/client/marketmetering/_client.py
stream ¤
stream(
*,
market_locations: list[MarketLocationRef],
directions: list[EnergyFlowDirection],
metric_types: list[MetricType],
start_time: datetime | None = None,
end_time: datetime | None = None,
resampling: ResamplingOptions | None = None,
revision_strategy: RevisionStrategy | None = None
) -> Receiver[MarketLocationSeries]
Get a receiver for streaming metering samples.
This method returns a channel receiver that can be used to receive Market Location sample series. The stream is managed internally and supports multiple receivers.
| PARAMETER | DESCRIPTION |
|---|---|
market_locations
|
List of Market Location references to stream.
TYPE:
|
directions
|
Energy-flow directions requested (IMPORT and/or EXPORT).
TYPE:
|
metric_types
|
Metric types to request (e.g., ACTIVE_ENERGY, ACTIVE_POWER).
TYPE:
|
start_time
|
Optional start time for historical data.
TYPE:
|
end_time
|
Optional end time. If omitted, stream continues in real-time.
TYPE:
|
resampling
|
Optional resampling options for aggregation.
TYPE:
|
revision_strategy
|
Optional revision strategy for the stream filter.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Receiver[MarketLocationSeries]
|
A channel receiver for MarketLocationSeries objects. |
Example
Source code in src/frequenz/client/marketmetering/_client.py
stream_samples
async
¤
stream_samples(
*,
market_locations: list[MarketLocationRef],
directions: list[EnergyFlowDirection],
metric_types: list[MetricType],
start_time: datetime | None = None,
end_time: datetime | None = None,
resampling: ResamplingOptions | None = None,
revision_strategy: RevisionStrategy | None = None
) -> AsyncIterator[MarketLocationSeries]
Stream metering samples for Market Locations.
Streams historical and/or real-time metering samples for one or more
Market Locations. The stream produces one MarketLocationSeries per
unique combination of Market Location, direction, and metric type.
| PARAMETER | DESCRIPTION |
|---|---|
market_locations
|
List of Market Location references to stream.
TYPE:
|
directions
|
Energy-flow directions requested (IMPORT and/or EXPORT).
TYPE:
|
metric_types
|
Metric types to request (e.g., ACTIVE_ENERGY, ACTIVE_POWER).
TYPE:
|
start_time
|
Optional start time for historical data. If omitted, stream starts from real-time data.
TYPE:
|
end_time
|
Optional end time. If omitted, stream continues in real-time.
TYPE:
|
resampling
|
Optional resampling options for aggregation.
TYPE:
|
revision_strategy
|
Optional revision strategy for the stream filter.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[MarketLocationSeries]
|
MarketLocationSeries objects containing samples for each combination |
AsyncIterator[MarketLocationSeries]
|
of Market Location, direction, and metric type. |
Example
async for series in client.stream_samples(
market_locations=[market_location],
directions=[EnergyFlowDirection.IMPORT],
metric_types=[MetricType.ACTIVE_ENERGY],
):
print(f"Location: {series.market_location_ref.market_location_id.value}")
for sample in series.samples:
print(f" {sample.sample_time}: {sample.value}")
Source code in src/frequenz/client/marketmetering/_client.py
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 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
update_market_location
async
¤
update_market_location(
*,
market_location_ref: MarketLocationRef,
update: MarketLocationUpdate,
expected_revision: int
) -> MarketLocationDetail
Update an existing Market Location.
| PARAMETER | DESCRIPTION |
|---|---|
market_location_ref
|
The reference ID of the location to update.
TYPE:
|
update
|
The fields to update.
TYPE:
|
expected_revision
|
The revision the caller expects to be the latest. This prevents lost updates when multiple callers modify the same Market Location concurrently. Pass the revision from the most recent read of the location.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationDetail
|
The updated Market Location with server-assigned metadata. |
Source code in src/frequenz/client/marketmetering/_client.py
upsert_samples
async
¤
upsert_samples(
samples_stream: AsyncIterator[
tuple[MarketLocationRef, MarketLocationSeries]
],
) -> AsyncIterator[UpsertResult]
Upsert a stream of metering samples.
| PARAMETER | DESCRIPTION |
|---|---|
samples_stream
|
An async iterator yielding (MarketLocationRef, MarketLocationSeries) tuples. Each series should contain exactly one sample.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[UpsertResult]
|
UpsertResult objects indicating success or failure for each sample. |
Source code in src/frequenz/client/marketmetering/_client.py
frequenz.client.marketmetering.MetricType ¤
Bases: Enum
Fundamental physical property being measured.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
ACTIVE_ENERGY
class-attribute
instance-attribute
¤
Active energy (e.g., kWh, Wh, MWh).
ACTIVE_POWER
class-attribute
instance-attribute
¤
Active power (e.g., kW, MW).
REACTIVE_ENERGY
class-attribute
instance-attribute
¤
Reactive energy (e.g., kVArh).
REACTIVE_POWER
class-attribute
instance-attribute
¤
Reactive power (e.g., kVAr, MVAr).
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified metric type.
frequenz.client.marketmetering.MetricUnit ¤
Bases: Enum
Unit of measurement for a sample value.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
KVAR
class-attribute
instance-attribute
¤
Kilovolt-ampere-reactive (kVAr).
KVARH
class-attribute
instance-attribute
¤
Kilovolt-ampere-reactive-hour (kVArh).
MVAR
class-attribute
instance-attribute
¤
Megavolt-ampere-reactive (MVAr).
MVARH
class-attribute
instance-attribute
¤
Megavolt-ampere-reactive-hour (MVArh).
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified unit.
VARH
class-attribute
instance-attribute
¤
Volt-ampere-reactive-hour (VArh).
frequenz.client.marketmetering.PaginationParams
dataclass
¤
Parameters for pagination.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
page_size
class-attribute
instance-attribute
¤
page_size: int | None = None
Maximum number of results to return.
page_token
class-attribute
instance-attribute
¤
page_token: str | None = None
Token to retrieve the next page of results.
Methods:¤
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
PaginationParams
|
The protobuf representation. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.ResamplingMethod ¤
Bases: Enum
Indicates how a returned sample was derived.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
DOWNSAMPLED
class-attribute
instance-attribute
¤
Sample is computed from finer-granularity data.
NATIVE
class-attribute
instance-attribute
¤
Sample is stored at this exact resolution.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified method.
UPSAMPLED
class-attribute
instance-attribute
¤
Sample is computed from coarser-granularity data.
frequenz.client.marketmetering.ResamplingOptions
dataclass
¤
Resampling options for Market Location time-series data.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
downsampling_method
class-attribute
instance-attribute
¤
downsampling_method: DownsamplingMethod = (
DownsamplingMethod.MEAN
)
Aggregation method applied when downsampling.
resolution
class-attribute
instance-attribute
¤
resolution: TimeResolution | None = None
Optional resampling resolution for the output time series.
Methods:¤
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
ResamplingOptions
|
The protobuf representation. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.RevisionSelection
dataclass
¤
Selection criteria for revisions of Market Location data.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
changed_fields
class-attribute
instance-attribute
¤
changed_fields: Iterable[MarketLocationChangedField] = (
field(default_factory=list)
)
Filter revisions by changed fields (only for REVISION_STRATEGY_ALL).
revision_strategy
class-attribute
instance-attribute
¤
revision_strategy: RevisionStrategy = (
RevisionStrategy.LATEST_ONLY
)
Strategy for selecting revisions.
Methods:¤
to_protobuf ¤
Convert to protobuf message.
| RETURNS | DESCRIPTION |
|---|---|
MarketLocationRevisionSelection
|
The protobuf representation. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.RevisionStrategy ¤
Bases: Enum
Strategy for selecting revisions of Market Location data.
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.SampleUpsertError
dataclass
¤
Structured error for a rejected sample upsert.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
error_code
instance-attribute
¤
error_code: SampleUpsertErrorCode
Machine-readable classification of the failure.
error_message
instance-attribute
¤
error_message: str
Human-readable diagnostic message for logging and debugging.
existing_sample
instance-attribute
¤
existing_sample: MarketLocationSample | None
The stored sample that prevented this upsert, if available.
Populated only for REVISION_CONFLICT and REVISION_TOO_OLD errors.
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(pb_obj: SampleUpsertError) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new SampleUpsertError instance. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.SampleUpsertErrorCode ¤
Bases: Enum
Error codes for sample upsert operations.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
INVALID_TIMESTAMP
class-attribute
instance-attribute
¤
The sample timestamp is invalid (e.g., misalignment).
MARKET_LOCATION_INACTIVE
class-attribute
instance-attribute
¤
The Market Location is inactive.
MARKET_LOCATION_NOT_FOUND
class-attribute
instance-attribute
¤
The Market Location does not exist.
REVISION_CONFLICT
class-attribute
instance-attribute
¤
The sample revision conflicts with an existing sample.
REVISION_TOO_OLD
class-attribute
instance-attribute
¤
The sample revision is older than the current revision.
STORAGE_FAILURE
class-attribute
instance-attribute
¤
Internal storage error.
UNIT_MISMATCH
class-attribute
instance-attribute
¤
The metric unit does not match the Market Location's unit.
UNKNOWN_ERROR
class-attribute
instance-attribute
¤
Unknown error.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified error.
UNSUPPORTED_DIRECTION
class-attribute
instance-attribute
¤
The direction is not supported by the Market Location.
UNSUPPORTED_METRIC_TYPE
class-attribute
instance-attribute
¤
The metric type is not supported by the Market Location.
frequenz.client.marketmetering.TimeResolution ¤
Bases: Enum
Time resolution for metering data.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
MIN_60
class-attribute
instance-attribute
¤
60-minute (1 hour) interval.
UNSPECIFIED
class-attribute
instance-attribute
¤
Unspecified resolution.
Methods:¤
to_timedelta ¤
to_timedelta() -> timedelta | None
Convert to a timedelta.
| RETURNS | DESCRIPTION |
|---|---|
timedelta | None
|
The timedelta representation, or None if unspecified. |
Source code in src/frequenz/client/marketmetering/types.py
frequenz.client.marketmetering.UpsertResult
dataclass
¤
Result of a sample upsert operation.
If error is None the upsert was accepted; otherwise it was rejected.
Source code in src/frequenz/client/marketmetering/types.py
Attributes¤
direction
instance-attribute
¤
direction: EnergyFlowDirection
Energy-flow direction of the sample (echoed from request).
error
instance-attribute
¤
error: SampleUpsertError | None
Error details if the upsert was rejected, None on success.
ingest_time
instance-attribute
¤
ingest_time: datetime | None
Server-side timestamp when the sample was ingested. Populated only on success.
market_location_ref
instance-attribute
¤
market_location_ref: MarketLocationRef
Reference to the Market Location.
metric_type
instance-attribute
¤
metric_type: MetricType
Metric type of the sample (echoed from request).
metric_unit
instance-attribute
¤
metric_unit: MetricUnit
Metric unit of the sample (echoed from request).
sample
instance-attribute
¤
sample: MarketLocationSample
The sample that was upserted (echoed from request).
Methods:¤
from_protobuf
classmethod
¤
from_protobuf(
pb_obj: UpsertMarketLocationSamplesStreamResponse,
) -> Self
Create from protobuf message.
| PARAMETER | DESCRIPTION |
|---|---|
pb_obj
|
The protobuf message.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
A new UpsertResult instance. |