Skip to main content

Reporting API client for Python

Project description

Frequenz Reporting API Client

Build Status PyPI Package Docs

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.2.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"
client = ReportingApiClient(service_address=SERVICE_ADDRESS)

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,
    )
]

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,
    )
]

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 --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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

frequenz-client-reporting-0.3.0.tar.gz (11.5 kB view hashes)

Uploaded Source

Built Distribution

frequenz_client_reporting-0.3.0-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page