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.9.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 resampling_period
parameter. For example, to resample data every 15 minutes, use a resampling_period
of timedelta(minutes=15).
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"),
resampling_period=timedelta(seconds=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"),
resampling_period=timedelta(seconds=1),
states=False, # Set to True to include state data
bounds=False, # Set to True to include metric bounds data
)
]
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 \
--states \
--bounds
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
File details
Details for the file frequenz-client-reporting-0.10.0.tar.gz
.
File metadata
- Download URL: frequenz-client-reporting-0.10.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e52fdc59cfcffb6d042ac016b3be7c1b4ced81e26635ca858791c7ef40bcd36d |
|
MD5 | 547ddb3402386c2554ef8b765d48cbba |
|
BLAKE2b-256 | 35606aeeb05982a47a860aa46600f02ca7de9f1504580ad31383f2363b4dbd65 |
Provenance
The following attestation bundles were made for frequenz-client-reporting-0.10.0.tar.gz
:
Publisher:
ci.yaml
on frequenz-floss/frequenz-client-reporting-python
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
frequenz_client_reporting-0.10.0.tar.gz
- Subject digest:
e52fdc59cfcffb6d042ac016b3be7c1b4ced81e26635ca858791c7ef40bcd36d
- Sigstore transparency entry: 150115652
- Sigstore integration time:
- Predicate type:
File details
Details for the file frequenz_client_reporting-0.10.0-py3-none-any.whl
.
File metadata
- Download URL: frequenz_client_reporting-0.10.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26df847244d32b68cabb57ad35d803ba01cdc7cb3c0eb811467a6ff45bf63c6f |
|
MD5 | fb76cfe43b11713468f66c4a59b7da23 |
|
BLAKE2b-256 | 84f498fc1745d80714e189dde2a5b6fb16d58ae524ff165829fe5438f70e5082 |
Provenance
The following attestation bundles were made for frequenz_client_reporting-0.10.0-py3-none-any.whl
:
Publisher:
ci.yaml
on frequenz-floss/frequenz-client-reporting-python
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
frequenz_client_reporting-0.10.0-py3-none-any.whl
- Subject digest:
26df847244d32b68cabb57ad35d803ba01cdc7cb3c0eb811467a6ff45bf63c6f
- Sigstore transparency entry: 150115653
- Sigstore integration time:
- Predicate type: