{"id":21974260,"url":"https://github.com/frequenz-floss/frequenz-client-reporting-python","last_synced_at":"2025-04-28T14:45:06.560Z","repository":{"id":227851494,"uuid":"772545916","full_name":"frequenz-floss/frequenz-client-reporting-python","owner":"frequenz-floss","description":"A python client for the Frequenz Reporting API","archived":false,"fork":false,"pushed_at":"2025-04-04T09:11:23.000Z","size":1884,"stargazers_count":0,"open_issues_count":12,"forks_count":5,"subscribers_count":4,"default_branch":"v0.x.x","last_synced_at":"2025-04-04T10:24:22.165Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frequenz-floss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-15T12:05:55.000Z","updated_at":"2025-04-01T15:23:22.000Z","dependencies_parsed_at":"2024-06-17T08:25:30.604Z","dependency_job_id":"33321302-554e-4b25-9aa0-8c43a385834d","html_url":"https://github.com/frequenz-floss/frequenz-client-reporting-python","commit_stats":null,"previous_names":["frequenz-floss/frequenz-client-reporting-python"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frequenz-floss%2Ffrequenz-client-reporting-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frequenz-floss%2Ffrequenz-client-reporting-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frequenz-floss%2Ffrequenz-client-reporting-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frequenz-floss%2Ffrequenz-client-reporting-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frequenz-floss","download_url":"https://codeload.github.com/frequenz-floss/frequenz-client-reporting-python/tar.gz/refs/heads/v0.x.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251332623,"owners_count":21572664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T15:40:21.855Z","updated_at":"2025-04-28T14:45:06.550Z","avatar_url":"https://github.com/frequenz-floss.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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.12.0\npip install frequenz-client-reporting==$VERSION\n```\n\n\n### Initialize the client\n\n```python\nfrom datetime import datetime, timedelta\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\"\nAPI_KEY = open('api_key.txt').read().strip()\nclient = ReportingApiClient(server_url=SERVER_URL, key=API_KEY)\n```\n\nBesides the `microgrid_id`, `component_id`s, `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\n`resampling_period=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        include_states=False, # Set to True to include state data\n        include_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=$(\u003capi_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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrequenz-floss%2Ffrequenz-client-reporting-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrequenz-floss%2Ffrequenz-client-reporting-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrequenz-floss%2Ffrequenz-client-reporting-python/lists"}