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 you want to install
VERSION=0.8.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 if needed
SERVER_URL = "grpc://reporting.api.frequenz.com:443?ssl=true"
API_KEY = open('api_key.txt').read().strip()
client = ReportingApiClient(server_url=SERVER_URL, key=API_KEY)
Besides the microgrid_id, component_ids, and metrics, start, and end time,
you can also set the sampling period for resampling using the resolution
parameter.
For example, to resample data every 15 minutes, use a resolution
of 900 seconds. The default is 1 second.
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"),
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"),
resolution=1,
)
]
Optionally convert the data to a pandas DataFrame
import pandas as pd
df = pd.DataFrame(data)
print(df)
Command line client tool
The package contains a command-line tool that can be used to request data from the reporting API.
reporting-cli \
--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 \
--format csv
In addition to the default CSV format the data can be output as individual samples or in dict
format.
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
Hashes for frequenz-client-reporting-0.9.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef207499e86da388970d64eaf67f1edc3695d790a489256a799d223ebdd9396d |
|
MD5 | 8c110d7632046c33d495b8ba269a3c62 |
|
BLAKE2b-256 | 61b2e41232e902a4a1cba5d21f9e137187a740a14226324910170be7127193ee |
Hashes for frequenz_client_reporting-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dc92aad2b43678d73a663234404fd69ca53ab9ecb7d78b28b3d48eb38e742d1 |
|
MD5 | b07a0600b9d88244b038cf8a33ea2036 |
|
BLAKE2b-256 | 65e08bbf84e1aba2916244ecf59de49a6d600d6d50771c4967da5525e5b68342 |