Reporting API client for Python
Project description
Frequenz Reporting API Client
Introduction
Reporting API client for Python
Supported Platforms
The following platforms are officially supported (tested):
- Python: 3.11
- Operating System: Ubuntu Linux 20.04
- Architectures: amd64, arm64
Contributing
If you want to know how to build this project and contribute to it, please check out the Contributing Guide.
Usage
Please also refer to examples for more detailed usage.
Installation
# Choose the version to install
VERSION=0.4.0
pip install frequenz-client-reporting==$VERSION
Initialize the client
from datetime import datetime
from frequenz.client.common.metric import Metric
from frequenz.client.reporting import ReportingApiClient
# Change server address
SERVICE_ADDRESS = "localhost:4711"
API_KEY = open('api_key.txt').read().strip()
client = ReportingApiClient(service_address=SERVICE_ADDRESS, key=API_KEY)
Query metrics for a single microgrid and component:
data = [
sample async for sample in
client.list_single_component_data(
microgrid_id=1,
component_id=100,
metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],
start_dt=datetime.fromisoformat("2024-05-01T00:00:00"),
end_dt=datetime.fromisoformat("2024-05-02T00:00:00"),
page_size=10000,
resolution=1,
)
]
Query metrics for multiple microgrids and components
# Set the microgrid ID and the component IDs that belong to the microgrid
# Multiple microgrids and components can be queried at once
microgrid_id1 = 1
component_ids1 = [100, 101, 102]
microgrid_id2 = 2
component_ids2 = [200, 201, 202]
microgrid_components = [
(microgrid_id1, component_ids1),
(microgrid_id2, component_ids2),
]
data = [
sample async for sample in
client.list_microgrid_components_data(
microgrid_components=microgrid_components,
metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],
start_dt=datetime.fromisoformat("2024-05-01T00:00:00"),
end_dt=datetime.fromisoformat("2024-05-02T00:00:00"),
page_size=10000,
resolution=1,
)
]
Optionally convert the data to a pandas DataFrame
import pandas as pd
df = pd.DataFrame(data)
print(df)
Command line client example
The example folder contains a simple client that can be used to query the reporting API from the command line:
python examples/client.py \
--url localhost:4711 \
--key=$(<api_key.txt)
--mid 42 \
--cid 23 \
--metrics AC_ACTIVE_POWER AC_REACTIVE_POWER \
--start 2024-05-01T00:00:00 \
--end 2024-05-02T00:00:00
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for frequenz-client-reporting-0.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e6849c902558e31b2cca40a8fd1d8a6bdc2620e000a94b7ce2c473a49f37210 |
|
MD5 | a032fc387b21b8285762c8457a581cf7 |
|
BLAKE2b-256 | 566a49e0b564c30ef05b1bff2201e7bbc5d207908a304a525fb67413ae0c8d69 |
Close
Hashes for frequenz_client_reporting-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51f86ed1de072274b690dcadf8e4f3c9b42b1582ff25fd49ed32d3d36c9ade61 |
|
MD5 | f250d9be1b9abdce40fdf9daa791934e |
|
BLAKE2b-256 | ddf8e6ea37a26d62ed22a330515fab25751073e4ae7d60472f4d91b79966f53d |