Python Client
| Category | Links |
|---|---|
| Documentation | |
| Stack | |
| Repository | |
| Testing & CI | |
| Release | |
| Package | |
| Quality | |
| Community | |
| License |
wattnet-client is the official Python client for the wattnet API. It maps every API endpoint to a client method and hands back a pandas DataFrame: no manual HTTP calls or JSON flattening required.
The full guide is in the Wattnet documentation.
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? UseWattnetRawClient. - Sync and async:
WattnetClientandWattnetRawClientfor scripts and notebooks,AsyncWattnetClientandAsyncWattnetRawClientfor asyncio applications. - Two ways to authenticate: a static bearer token, or the
client_idandclient_secretof 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 for every method exercised against the real API, with actual DataFrame outputs saved in the notebook.
Installation
pip install wattnet-client
From source
git clone https://github.com/wattnet/wattnet-client-python.git
cd wattnet-client-python
poetry install
Quickstart
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:
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.
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. 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.
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:
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) use AsyncWattnetRawClient. It exposes the same methods as WattnetRawClient, every one of them a coroutine, and returns raw JSON. It is built on aiohttp and does not import pandas. If you prefer DataFrames, AsyncWattnetClient is its counterpart of WattnetClient: the same methods as coroutines returning a pandas.DataFrame.
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())
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 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:
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 asinvalid_resolution, orNoneif the server sends none).
Contributing
Contributions are welcome. See CONTRIBUTING.md for environment setup, code style, and how to run the tests.
License
This repository is licensed under the Apache License 2.0.
See the LICENSE file for more details.
Funding and Acknowledgments
This work was developed within the GreenDIGIT project, funded by the European Union's Horizon Europe research and innovation programme under grant agreement No. 101131207, and by the Swiss State Secretariat for Education, Research and Innovation (SERI).
© 2026 Spanish National Research Council (CSIC). All rights reserved.
Metadata
Release files for wattnet-client 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wattnet_client-1.0.0.tar.gz | 37.8 kB | With provenance | Details for wattnet_client-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wattnet_client-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for wattnet_client-1.0.0-py3-none-any.whl |
Total release size: 75.6 kB
Release files / wattnet_client-1.0.0.tar.gz
| Download URL | wattnet_client-1.0.0.tar.gz |
|---|---|
| Size | 37.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2637a8a9793aae6d5709f7f54d456cd419968c80e0dc477a1e83c104170d130b
|
|
BLAKE2b-256 checksum How to use checksums |
8f5b54f8cfb5aaf82af30ce98343838a161937edc60f97f68111a8926526d47d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / wattnet_client-1.0.0-py3-none-any.whl
| Download URL | wattnet_client-1.0.0-py3-none-any.whl |
|---|---|
| Size | 37.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3e11b91da1fe7883f84270afaafeda3696f1c1cd034c82f055feebc65b193736
|
|
BLAKE2b-256 checksum How to use checksums |
f2a882bea28dbc417de268e756baff849c80adb5d1f2d10724b66e7b51ddd2a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for wattnet-client 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for wattnet_client-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.