Metadata-Version: 2.4
Name: wattnet-client
Version: 1.0.0
Summary: Official Python client for the wattnet API: electricity generation, load, and carbon and water footprint data as pandas DataFrames
License: Apache-2.0
License-File: LICENSE
Keywords: energy,electricity,carbon,carbon-footprint,water,water-footprint,water-impact,environmental-score,api,client,pandas,dataframe,sustainability,wattnet
Author: Jaime Iglesias Blanco
Author-email: iglesias@ifca.es
Requires-Python: >=3.11.5,<3.16
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: aiohttp (>=3.10.0,<4.0.0)
Requires-Dist: pandas (>=2.2.0,<3.0.0) ; python_version < "3.15"
Requires-Dist: pandas (>=3.0.6) ; python_version >= "3.15"
Requires-Dist: requests (>=2.33.0,<3.0.0)
Project-URL: Documentation, https://docs.wattnet.eu/user-guide/python-client/python-client-quickstart/
Project-URL: Homepage, https://wattnet.eu
Project-URL: Repository, https://github.com/wattnet/wattnet-client-python
Description-Content-Type: text/markdown

<div align="left">
  <picture>
    <source media="(prefers-color-scheme: dark)"
            srcset="https://github.com/wattnet/.github/raw/main/images/wattnet-logo-full-dark-transparent-cropped.png" />
    <source media="(prefers-color-scheme: light)"
            srcset="https://github.com/wattnet/.github/raw/main/images/wattnet-logo-full-light-transparent-cropped.png" />
    <img src="https://github.com/wattnet/.github/raw/main/images/wattnet-logo-full-light-transparent-cropped.png"
         alt="Wattnet Logo"
         width="300" />
  </picture>
</div>

# Python Client

| Category      | Links                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Documentation | [![Docs](https://img.shields.io/badge/User%20Docs-docs.wattnet.eu-2E63C2?logo=zensical&logoColor=white&labelColor=1E293B)](https://docs.wattnet.eu/user-guide/python-client/python-client-quickstart/)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Stack         | [![pandas](https://img.shields.io/badge/pandas-475569?logo=pandas&logoColor=white)](https://pandas.pydata.org/) [![aiohttp](https://img.shields.io/badge/aiohttp-475569?logo=aiohttp&logoColor=white)](https://docs.aiohttp.org/)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Repository    | [![Contributors](https://img.shields.io/github/contributors/wattnet/wattnet-client-python?label=Contributors&color=1E293B&logo=github&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/graphs/contributors) [![Stars](https://img.shields.io/github/stars/wattnet/wattnet-client-python?style=flat&label=Stars&color=1E293B&logo=github&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/stargazers)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Testing & CI  | [![CI](https://img.shields.io/github/actions/workflow/status/wattnet/wattnet-client-python/ci.yml?branch=main&label=CI&logo=githubactions&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/actions/workflows/ci.yml) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-0F766E?logo=pre-commit&logoColor=white&labelColor=1E293B)](https://github.com/pre-commit/pre-commit) [![Ruff lint](https://img.shields.io/badge/Lint-Ruff-0F766E?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTAgNjIyIj48cGF0aCBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0yMDcgMEwxOTYgMTBWNDFMMTg2IDUySDE1N0wxNDYgNjJWMTQ1TDEzNiAxNTZIMTA3TDk3IDE2NlYyMjNMODYgMjMzSDU3TDQ3IDI0NFYzMDFMMzYgMzExSDEwTDAgMzIxVjM1MkwxMCAzNjNIMTQ1TDE1NiAzNzNWNDMwTDE0NSA0NDFIMTE2TDEwNiA0NTFWNTA4TDk2IDUxOEg2Nkw1NiA1MjlWNjEyTDY2IDYyMkgxNTBMMTYwIDYxMlY1NzBIMjAyTDIxMiA1NjBWNTI5TDIyMiA1MThIMjUxTDI2MiA1MDhWNDc3TDI3MiA0NjZIMzAxTDMxMiA0NTZWNDI1TDMyMiA0MTVIMzUxTDM2MSA0MDRWMzczTDM3MiAzNjNINDAxTDQxMSAzNTJWMzIxTDQyMiAzMTFINDUxTDQ2MSAzMDFWMjE4TDQ1MSAyMDdINDIxTDQxMCAxOTdWMTY2TDQyMSAxNTZINDUwTDQ2MCAxNDVWMTE0TDQ3MSAxMDRINTAwTDUxMCA5M1YxMEw1MDAgMEgyMDdaTTE2OCA0NDFMMTU4IDQ1MVY1MDhMMTQ3IDUxOEgxMThMMTA4IDUyOVY1NjBMMTE4IDU3MEgxNjBWNTI5TDE3MCA1MThIMTk5TDIxMCA1MDhWNDc3TDIyMCA0NjZIMjQ5TDI2MCA0NTZWNDI1TDI3MCA0MTVIMjk5TDMxMCA0MDRWMzczTDMyMCAzNjNIMzQ5TDM1OSAzNTJWMzIxTDM3MCAzMTFIMzk5TDQwOSAzMDFWMjcwTDM5OSAyNTlIMzE5TDMwOCAyNDlWMjE4TDMxOSAyMDdIMzQ4TDM1OCAxOTdWMTY2TDM2OSAxNTZIMzk4TDQwOCAxNDVWMTE0TDQxOSAxMDRINDQ4TDQ1OCA5M1Y2Mkw0NDggNTJIMjA5TDE5OCA2MlYxNDVMMTg4IDE1NkgxNTlMMTQ5IDE2NlYyMjNMMTM4IDIzM0gxMDlMOTkgMjQ0VjMwMUwxMDkgMzExSDE5N0wyMDggMzIxVjQzMEwxOTcgNDQxSDE2OFoiLz48L3N2Zz4%3D&logoColor=white&labelColor=1E293B)](https://docs.astral.sh/ruff/linter/) |
| Release       | [![Release](https://img.shields.io/github/v/release/wattnet/wattnet-client-python?label=Release&color=3B5B8A&logo=github&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/releases) [![Publish](https://img.shields.io/github/actions/workflow/status/wattnet/wattnet-client-python/publish.yml?label=Publish&logo=githubactions&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/actions/workflows/publish.yml) [![Release Please](https://img.shields.io/github/actions/workflow/status/wattnet/wattnet-client-python/release-please.yml?branch=main&label=Release%20Please&logo=githubactions&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/actions/workflows/release-please.yml)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| Package       | [![PyPI](https://img.shields.io/pypi/v/wattnet-client?label=PyPI&color=9C5A32&logo=pypi&logoColor=white&labelColor=1E293B)](https://pypi.org/project/wattnet-client/) [![Python](https://img.shields.io/pypi/pyversions/wattnet-client?label=Python&color=9C5A32&logo=python&logoColor=white&labelColor=1E293B)](https://pypi.org/project/wattnet-client/) [![Downloads](https://img.shields.io/pepy/dt/wattnet-client?label=Downloads&color=9C5A32&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0iI2ZmZiI%2BPHBhdGggZD0iTTExIDNoMnY5LjE3bDMuNTktMy41OEwxOCAxMGwtNiA2LTYtNiAxLjQxLTEuNDFMMTEgMTIuMTdWM3oiLz48cGF0aCBkPSJNNCAxOWgxNnYySDR6Ii8%2BPC9zdmc%2B&logoColor=white&labelColor=1E293B)](https://pepy.tech/projects/wattnet-client)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Quality       | [![Status](https://img.shields.io/badge/Status-Production%2FStable-4A8118?labelColor=1E293B)](https://pypi.org/project/wattnet-client/) [![Coverage](https://img.shields.io/codecov/c/github/wattnet/wattnet-client-python?label=Coverage&logo=codecov&logoColor=white&labelColor=1E293B)](https://codecov.io/gh/wattnet/wattnet-client-python) [![Ruff format](https://img.shields.io/badge/Format-Ruff-4A8118?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTAgNjIyIj48cGF0aCBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0yMDcgMEwxOTYgMTBWNDFMMTg2IDUySDE1N0wxNDYgNjJWMTQ1TDEzNiAxNTZIMTA3TDk3IDE2NlYyMjNMODYgMjMzSDU3TDQ3IDI0NFYzMDFMMzYgMzExSDEwTDAgMzIxVjM1MkwxMCAzNjNIMTQ1TDE1NiAzNzNWNDMwTDE0NSA0NDFIMTE2TDEwNiA0NTFWNTA4TDk2IDUxOEg2Nkw1NiA1MjlWNjEyTDY2IDYyMkgxNTBMMTYwIDYxMlY1NzBIMjAyTDIxMiA1NjBWNTI5TDIyMiA1MThIMjUxTDI2MiA1MDhWNDc3TDI3MiA0NjZIMzAxTDMxMiA0NTZWNDI1TDMyMiA0MTVIMzUxTDM2MSA0MDRWMzczTDM3MiAzNjNINDAxTDQxMSAzNTJWMzIxTDQyMiAzMTFINDUxTDQ2MSAzMDFWMjE4TDQ1MSAyMDdINDIxTDQxMCAxOTdWMTY2TDQyMSAxNTZINDUwTDQ2MCAxNDVWMTE0TDQ3MSAxMDRINTAwTDUxMCA5M1YxMEw1MDAgMEgyMDdaTTE2OCA0NDFMMTU4IDQ1MVY1MDhMMTQ3IDUxOEgxMThMMTA4IDUyOVY1NjBMMTE4IDU3MEgxNjBWNTI5TDE3MCA1MThIMTk5TDIxMCA1MDhWNDc3TDIyMCA0NjZIMjQ5TDI2MCA0NTZWNDI1TDI3MCA0MTVIMjk5TDMxMCA0MDRWMzczTDMyMCAzNjNIMzQ5TDM1OSAzNTJWMzIxTDM3MCAzMTFIMzk5TDQwOSAzMDFWMjcwTDM5OSAyNTlIMzE5TDMwOCAyNDlWMjE4TDMxOSAyMDdIMzQ4TDM1OCAxOTdWMTY2TDM2OSAxNTZIMzk4TDQwOCAxNDVWMTE0TDQxOSAxMDRINDQ4TDQ1OCA5M1Y2Mkw0NDggNTJIMjA5TDE5OCA2MlYxNDVMMTg4IDE1NkgxNTlMMTQ5IDE2NlYyMjNMMTM4IDIzM0gxMDlMOTkgMjQ0VjMwMUwxMDkgMzExSDE5N0wyMDggMzIxVjQzMEwxOTcgNDQxSDE2OFoiLz48L3N2Zz4%3D&logoColor=white&labelColor=1E293B)](https://docs.astral.sh/ruff/formatter/)                                                                                       |
| Community     | [![Contributing](https://img.shields.io/badge/Contributing-guidelines-5374A7?logo=github&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/blob/main/CONTRIBUTING.md) [![Code of Conduct](https://img.shields.io/badge/Code%20of%20Conduct-3.0-5374A7?logo=contributorcovenant&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/blob/main/CODE_OF_CONDUCT.md) [![Security](https://img.shields.io/badge/Security-policy-5374A7?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0iI2ZmZiI%2BPHBhdGggZD0iTTcgMTBWN2E1IDUgMCAwIDEgMTAgMHYzaDFhMiAyIDAgMCAxIDIgMnY4YTIgMiAwIDAgMS0yIDJINmEyIDIgMCAwIDEtMi0ydi04YTIgMiAwIDAgMSAyLTJoMXptMiAwaDZWN2EzIDMgMCAxIDAtNiAwdjN6Ii8%2BPC9zdmc%2B&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/blob/main/SECURITY.md) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-5374A7?logo=conventionalcommits&logoColor=white&labelColor=1E293B)](https://www.conventionalcommits.org/)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| License       | [![Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-64748B?logo=opensourceinitiative&logoColor=white&labelColor=1E293B)](https://github.com/wattnet/wattnet-client-python/blob/main/LICENSE)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

`wattnet-client` is the official Python client for the [wattnet API](https://github.com/wattnet/wattnet-api). It maps every API endpoint to a client method and hands back a [pandas](https://pandas.pydata.org/) `DataFrame`: no manual HTTP calls or JSON flattening required.

The full guide is in the [Wattnet documentation](https://docs.wattnet.eu/user-guide/python-client/python-client-quickstart/).

## Features

- **One method per endpoint**: `client.get_generation(...)`, `client.get_footprints(...)`, etc., mirroring the API 1:1.
- **DataFrames by default**: every method returns a tidy `pandas.DataFrame`. Need the raw JSON instead? Use `WattnetRawClient`.
- **Sync and async**: `WattnetClient` and `WattnetRawClient` for scripts and notebooks, `AsyncWattnetClient` and `AsyncWattnetRawClient` for asyncio applications.
- **Two ways to authenticate**: a static bearer token, or the `client_id` and `client_secret` of a wattnet credential; the library fetches and caches tokens for you.
- **Typed, autocomplete-friendly**: zone codes, production types, footprint scopes, etc. are typed for IDE/Jupyter tab-completion.

See [`examples/quickstart.ipynb`](examples/quickstart.ipynb) for every method exercised against the real API, with actual DataFrame outputs saved in the notebook.

## Installation

```bash
pip install wattnet-client
```

### From source

```bash
git clone https://github.com/wattnet/wattnet-client-python.git
cd wattnet-client-python
poetry install
```

## Quickstart

```python
from wattnet.client import WattnetClient

# Option 1: a pre-issued bearer token
client = WattnetClient(token="<your-token>")

# Option 2: a wattnet credential, the client fetches and caches a token for you
client = WattnetClient(
    client_id="<your-client-id>", client_secret="<your-client-secret>"
)

# Every call returns a pandas DataFrame
df = client.get_generation(zone="ES", production_type="solar")
df = client.get_footprints(zone="ES", footprint_type="carbon", scope="life-cycle")
df = client.get_environmental_score(
    zone="ES", aggregate=True, start="2026-01-01", end="2026-02-01"
)
```

Filter by coordinates instead of a zone code:

```python
df = client.get_load(lat=40.4, lon=-3.7)
```

Every time-series `DataFrame` has a `timestamp` column parsed as a tz-aware
(UTC) `datetime64[ns, UTC]`, ready to plot or resample without any manual
conversion. Omit `zone` (and other filter params) to get every zone back in
a single call instead of querying one at a time.

The columns come in the same order in every method: first when (`timestamp`,
or `start` and `end` for an aggregate), then what the series is (`zone`, the
other zone of a flow, the type and the `scope`), then `value` and `unit`, then
the quality and the provenance of the data (`valid`, `zone_status`,
`data_state`, `datasource`...), and `updated_at` last.

### Updated at and long ranges

Every time-series `DataFrame` has `timestamp`, `value` and `updated_at`, the moment that version of the value was stored (tz-aware, UTC).

A year at 15 minutes is a lot of rows. The series endpoints (`get_generation`, `get_load`, `get_imports`, `get_exports`, `get_mix`, `get_footprints`, `get_impacts` and `get_environmental_score`) take `resolution="1h"` or `"1d"` to get each hour or day (UTC) averaged by the API: far fewer rows and bytes, and faster.

```python
df = client.get_generation(
    zone="ES", start="2026-01-01", end="2026-11-01", resolution="1d"
)
```

The answers are compressed by default (`compress=True`; gzip, and `br` or `zstd` if their packages are installed) and decompressed for you. `WattnetClient(..., compress=False)` asks for none.

### Authentication

A credential (`client_id` and `client_secret`) is created in the [developer portal](https://developers.wattnet.eu). The client exchanges it for a bearer token with the OAuth 2.0 `client_credentials` grant the first time it's needed, keeps the token in memory, and renews it once 80 % of its lifetime has passed (but never later than a minute before it expires). If the API still rejects the cached token as expired, the client refreshes it and retries the request once.

```python
client = WattnetClient(
    client_id="<your-client-id>", client_secret="<your-client-secret>"
)
```

Read the secret from an environment variable or a secrets manager rather than writing it in code. The token endpoint is discovered from the OpenID Connect issuer (`https://auth.wattnet.eu/realms/wattnet`).

### Raw JSON access

If you need the untouched API response instead of a DataFrame, use `WattnetRawClient`: it exposes the exact same methods:

```python
from wattnet.client import WattnetRawClient

raw = WattnetRawClient(token="<your-token>")
payload = raw.get_generation(zone="ES")  # list[dict], straight from the API
```

### Async client

For asyncio applications (for example the [wattnet Home Assistant integration](https://github.com/wattnet/wattnet-home-assistant)) use `AsyncWattnetRawClient`. It exposes the same methods as `WattnetRawClient`, every one of them a coroutine, and returns raw JSON. It is built on [aiohttp](https://docs.aiohttp.org/) and does not import pandas. If you prefer DataFrames, `AsyncWattnetClient` is its counterpart of `WattnetClient`: the same methods as coroutines returning a `pandas.DataFrame`.

```python
import asyncio

from wattnet.client import AsyncWattnetRawClient


async def main() -> None:
    async with AsyncWattnetRawClient(token="<your-token>") as client:
        zones = await client.get_zones()
        footprints = await client.get_footprints(zone="ES", footprint_type="carbon")


asyncio.run(main())
```

```python
from wattnet.client import AsyncWattnetClient

async with AsyncWattnetClient(token="<your-token>") as client:
    df = await client.get_footprints(zone="ES", footprint_type="carbon")
```

Pass your own `aiohttp.ClientSession` with `session=...` to reuse an existing connection pool. A session you supply is never closed by the client. Authentication, retries, `Retry-After` handling and the token refresh on a 401 behave exactly as in the synchronous clients. 

## Available methods

| Method                                                                                                         | API endpoint               | Description                                                  |
| -------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------ |
| `get_zones()`                                                                                                  | `GET /zones`               | Metadata and neighbours for all supported zones              |
| `get_generation(...)`                                                                                          | `GET /generation`          | Electricity generation by production type                    |
| `get_load(...)`                                                                                                | `GET /load`                | Total electricity demand                                     |
| `get_imports(...)`                                                                                             | `GET /imports`             | Electricity imports, optionally filtered by origin zone      |
| `get_exports(...)`                                                                                             | `GET /exports`             | Electricity exports, optionally filtered by destination zone |
| `get_mix(...)`                                                                                                 | `GET /mix`                 | Flow-traced generation mix by production type                |
| `get_footprints(...)`                                                                                          | `GET /footprints`          | Carbon/water footprint of consumption                        |
| `get_impacts(...)`                                                                                             | `GET /impacts`             | Water impact of consumption                                  |
| `get_environmental_score(...)`                                                                                 | `GET /environmental-score` | EnvironmentalScore (0–100) of consumption                    |
| `get_flow_share(...)`                                                                                          | `GET /flow-share`          | Share of a zone's production exported to each destination    |
| `get_mix_share(...)`                                                                                           | `GET /mix-share`           | Share of a zone's mix coming from each origin                |
| `get_footprint_share(...)`                                                                                     | `GET /footprint-share`     | Footprint decomposed by origin zone                          |
| `get_impact_share(...)`                                                                                        | `GET /impact-share`        | Impact decomposed by origin zone                             |
| `get_factors(...)`                                                                                             | `GET /factors`             | Global emission/consumption factors                          |
| `get_status()` / `get_status_storage()` / `get_status_entsoe()` / `get_status_elexon()` / `get_status_epias()` | `GET /status[/...]`        | Health of the API and its upstream dependencies              |

Every method's parameters mirror the corresponding API endpoint's query parameters exactly, see each method's docstring/type hints, or the [wattnet-api docs](https://api.wattnet.eu/docs) for the full parameter reference.

`get_zones()` and `get_factors(...)` are cached in memory per client instance for an hour (they're near-static reference data): repeated calls within that window don't hit the network again.

## Configuration

| Constructor argument | Environment variable      | Default                                 |
| --------------------- | -------------------------- | ---------------------------------------- |
| `base_url`            | `WATTNET_API_BASE_URL`     | `https://api.wattnet.eu/v1`               |
| `issuer_url`          | `WATTNET_ISSUER_URL`       | `https://auth.wattnet.eu/realms/wattnet`  |
| `token_url`           | `WATTNET_TOKEN_URL`        | read from the issuer's discovery document |

Other constructor options: `session` (bring your own `requests.Session`), `timeout`, `retry_count`, `retry_delay` and `compress` (default `True`: ask the API for compressed answers).

Requests are retried up to `retry_count` times (default 3, waiting `retry_delay` seconds between attempts) on connection/timeout errors and on `429`/`5xx` responses, a `429` waits for the `Retry-After` value the API sends instead of the fixed delay, when present. A `401` always triggers one token refresh + retry, independent of `retry_count`.

`WattnetClient`/`WattnetRawClient` support the context manager protocol, closing
the underlying HTTP session on exit:

```python
with WattnetClient(token="<your-token>") as client:
    df = client.get_zones()
```

`repr(client)` shows the base URL and auth mode (e.g. `WattnetClient(base_url='https://api.wattnet.eu/v1', auth=StaticTokenProvider)`): never any credentials.

## Error handling

All errors raised by this library derive from `wattnet.client.WattnetError`:

- `ConfigurationError`: the client was instantiated with invalid/incomplete auth arguments.
- `AuthenticationError`: invalid token or credentials.
- `WattnetAPIError`: the API returned a non-2xx response; carries `.status_code`, `.detail` (a sentence for a person) and `.code` (a stable identifier for a program, such as `invalid_resolution`, or `None` if the server sends none).

## Contributing

Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for environment setup, code style, and how to run the tests.

## License

This repository is licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).

See the [LICENSE](LICENSE) file for more details.

## Funding and Acknowledgments

This work was developed within the [GreenDIGIT](https://greendigit-project.eu/) project, funded by the European Union's Horizon Europe research and innovation programme under grant agreement No. [101131207](https://cordis.europa.eu/project/id/101131207), and by the Swiss State Secretariat for Education, Research and Innovation (SERI).

<img src="https://github.com/wattnet/.github/raw/main/images/GreenDIGIT logo color horizontal2.png" alt="GreenDIGIT Logo" width="230" align="right"/>
<img src="https://github.com/wattnet/.github/raw/main/images/EN_FundedbytheEU_RGB_POS.png" alt="EU Funded Logo" width="260" align="left"/>
<img src="https://github.com/wattnet/.github/raw/main/images/Flag_of_Switzerland.svg" alt="Swiss State Secretariat for Education, Research and Innovation (SERI)" height="50" align="left"/>
<br clear="all"/>

##### © 2026 Spanish National Research Council (CSIC). All rights reserved.

