frequenz-client-reporting


Namefrequenz-client-reporting JSON
Version 0.10.0 PyPI version JSON
download
home_pageNone
SummaryReporting API client for Python
upload_time2024-11-20 09:18:08
maintainerNone
docs_urlNone
authorNone
requires_python<4,>=3.11
licenseMIT
keywords frequenz python lib library client-reporting client reporting api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Frequenz Reporting API Client

[![Build Status](https://github.com/frequenz-floss/frequenz-client-reporting-python/actions/workflows/ci.yaml/badge.svg)](https://github.com/frequenz-floss/frequenz-client-reporting-python/actions/workflows/ci.yaml)
[![PyPI Package](https://img.shields.io/pypi/v/frequenz-client-reporting)](https://pypi.org/project/frequenz-client-reporting/)
[![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-client-reporting-python/)

## 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](CONTRIBUTING.md).


## Usage

Please also refer to [examples](https://github.com/frequenz-floss/frequenz-client-reporting-python/tree/HEAD/examples) for more detailed usage.

### Installation

```bash
# Choose the version you want to install
VERSION=0.9.0
pip install frequenz-client-reporting==$VERSION
```


### Initialize the client

```python
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:

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

```python
# 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

```python
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.
```bash
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "frequenz-client-reporting",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.11",
    "maintainer_email": null,
    "keywords": "frequenz, python, lib, library, client-reporting, client, reporting, api",
    "author": null,
    "author_email": "Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>",
    "download_url": "https://files.pythonhosted.org/packages/35/60/6aeeb05982a47a860aa46600f02ca7de9f1504580ad31383f2363b4dbd65/frequenz-client-reporting-0.10.0.tar.gz",
    "platform": null,
    "description": "# Frequenz Reporting API Client\n\n[![Build Status](https://github.com/frequenz-floss/frequenz-client-reporting-python/actions/workflows/ci.yaml/badge.svg)](https://github.com/frequenz-floss/frequenz-client-reporting-python/actions/workflows/ci.yaml)\n[![PyPI Package](https://img.shields.io/pypi/v/frequenz-client-reporting)](https://pypi.org/project/frequenz-client-reporting/)\n[![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-client-reporting-python/)\n\n## Introduction\n\nReporting API client for Python\n\n## Supported Platforms\n\nThe following platforms are officially supported (tested):\n\n- **Python:** 3.11\n- **Operating System:** Ubuntu Linux 20.04\n- **Architectures:** amd64, arm64\n\n## Contributing\n\nIf you want to know how to build this project and contribute to it, please\ncheck out the [Contributing Guide](CONTRIBUTING.md).\n\n\n## Usage\n\nPlease also refer to [examples](https://github.com/frequenz-floss/frequenz-client-reporting-python/tree/HEAD/examples) for more detailed usage.\n\n### Installation\n\n```bash\n# Choose the version you want to install\nVERSION=0.9.0\npip install frequenz-client-reporting==$VERSION\n```\n\n\n### Initialize the client\n\n```python\nfrom datetime import datetime\n\nfrom frequenz.client.common.metric import Metric\nfrom frequenz.client.reporting import ReportingApiClient\n\n# Change server address if needed\nSERVER_URL = \"grpc://reporting.api.frequenz.com:443?ssl=true\"\nAPI_KEY = open('api_key.txt').read().strip()\nclient = ReportingApiClient(server_url=SERVER_URL, key=API_KEY)\n```\n\nBesides the microgrid_id, component_ids, and metrics, start, and end time,\nyou can also set the sampling period for resampling using the `resampling_period`\nparameter. For example, to resample data every 15 minutes, use a `resampling_period`\nof timedelta(minutes=15).\n\n### Query metrics for a single microgrid and component:\n\n```python\ndata = [\n    sample async for sample in\n    client.list_single_component_data(\n        microgrid_id=1,\n        component_id=100,\n        metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],\n        start_dt=datetime.fromisoformat(\"2024-05-01T00:00:00\"),\n        end_dt=datetime.fromisoformat(\"2024-05-02T00:00:00\"),\n        resampling_period=timedelta(seconds=1),\n    )\n]\n```\n\n\n### Query metrics for multiple microgrids and components\n\n```python\n# Set the microgrid ID and the component IDs that belong to the microgrid\n# Multiple microgrids and components can be queried at once\nmicrogrid_id1 = 1\ncomponent_ids1 = [100, 101, 102]\nmicrogrid_id2 = 2\ncomponent_ids2 = [200, 201, 202]\nmicrogrid_components = [\n    (microgrid_id1, component_ids1),\n    (microgrid_id2, component_ids2),\n]\n\ndata = [\n    sample async for sample in\n    client.list_microgrid_components_data(\n        microgrid_components=microgrid_components,\n        metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],\n        start_dt=datetime.fromisoformat(\"2024-05-01T00:00:00\"),\n        end_dt=datetime.fromisoformat(\"2024-05-02T00:00:00\"),\n        resampling_period=timedelta(seconds=1),\n        states=False, # Set to True to include state data\n        bounds=False, # Set to True to include metric bounds data\n    )\n]\n```\n\n### Optionally convert the data to a pandas DataFrame\n\n```python\nimport pandas as pd\ndf = pd.DataFrame(data)\nprint(df)\n```\n\n## Command line client tool\n\nThe package contains a command-line tool that can be used to request data from the reporting API.\n```bash\nreporting-cli \\\n    --url localhost:4711 \\\n    --key=$(<api_key.txt)\n    --mid 42 \\\n    --cid 23 \\\n    --metrics AC_ACTIVE_POWER AC_REACTIVE_POWER \\\n    --start 2024-05-01T00:00:00 \\\n    --end 2024-05-02T00:00:00 \\\n    --format csv \\\n    --states \\\n    --bounds\n```\nIn addition to the default CSV format the data can be output as individual samples or in `dict` format.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Reporting API client for Python",
    "version": "0.10.0",
    "project_urls": {
        "Changelog": "https://github.com/frequenz-floss/frequenz-client-reporting-python/releases",
        "Documentation": "https://frequenz-floss.github.io/frequenz-client-reporting-python/",
        "Issues": "https://github.com/frequenz-floss/frequenz-client-reporting-python/issues",
        "Repository": "https://github.com/frequenz-floss/frequenz-client-reporting-python",
        "Support": "https://github.com/frequenz-floss/frequenz-client-reporting-python/discussions/categories/support"
    },
    "split_keywords": [
        "frequenz",
        " python",
        " lib",
        " library",
        " client-reporting",
        " client",
        " reporting",
        " api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "84f498fc1745d80714e189dde2a5b6fb16d58ae524ff165829fe5438f70e5082",
                "md5": "fb76cfe43b11713468f66c4a59b7da23",
                "sha256": "26df847244d32b68cabb57ad35d803ba01cdc7cb3c0eb811467a6ff45bf63c6f"
            },
            "downloads": -1,
            "filename": "frequenz_client_reporting-0.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fb76cfe43b11713468f66c4a59b7da23",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.11",
            "size": 10758,
            "upload_time": "2024-11-20T09:18:06",
            "upload_time_iso_8601": "2024-11-20T09:18:06.539299Z",
            "url": "https://files.pythonhosted.org/packages/84/f4/98fc1745d80714e189dde2a5b6fb16d58ae524ff165829fe5438f70e5082/frequenz_client_reporting-0.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "35606aeeb05982a47a860aa46600f02ca7de9f1504580ad31383f2363b4dbd65",
                "md5": "547ddb3402386c2554ef8b765d48cbba",
                "sha256": "e52fdc59cfcffb6d042ac016b3be7c1b4ced81e26635ca858791c7ef40bcd36d"
            },
            "downloads": -1,
            "filename": "frequenz-client-reporting-0.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "547ddb3402386c2554ef8b765d48cbba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.11",
            "size": 12506,
            "upload_time": "2024-11-20T09:18:08",
            "upload_time_iso_8601": "2024-11-20T09:18:08.411972Z",
            "url": "https://files.pythonhosted.org/packages/35/60/6aeeb05982a47a860aa46600f02ca7de9f1504580ad31383f2363b4dbd65/frequenz-client-reporting-0.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 09:18:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "frequenz-floss",
    "github_project": "frequenz-client-reporting-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "frequenz-client-reporting"
}
        
Elapsed time: 0.51290s