Asynchronous Python client providing energy/gas prices from EnergyZero
Project description
Asynchronous Python client for the EnergyZero API.
About
A python package with which you can retrieve the dynamic energy/gas prices from EnergyZero and can therefore also be used for third parties who purchase their energy via EnergyZero, such as:
Installation
pip install energyzero
Example
import asyncio
from datetime import UTC, datetime, timedelta
from energyzero import EnergyZero, Interval, PriceType
async def main() -> None:
"""Fetch today/tomorrow energy prices using the REST backend (default)."""
async with EnergyZero() as client:
today = datetime.now(UTC).astimezone().date()
tomorrow = today + timedelta(days=1)
electricity_today = await client.get_electricity_prices(
start_date=today,
interval=Interval.QUARTER,
price_type=PriceType.ALL_IN,
)
gas_today = await client.get_gas_prices(
start_date=today,
price_type=PriceType.ALL_IN,
)
# Loop over additional days as needed
electricity_tomorrow = await client.get_electricity_prices(
start_date=tomorrow,
interval=Interval.HOUR,
price_type=PriceType.MARKET_WITH_VAT,
)
gas_tomorrow = await client.get_gas_prices(
start_date=tomorrow,
price_type=PriceType.MARKET,
)
print(electricity_today.average_price, gas_today.current_price)
print(electricity_tomorrow.average_price, gas_tomorrow.current_price)
if __name__ == "__main__":
asyncio.run(main())
More examples can be found in the examples folder.
examples/graphql/*targets the GraphQL backend (multi-day ranges).examples/rest/*shows REST API usage (single-day requests, quarter-hour data).
Data
[!NOTE] Currently tested primarily with day-ahead pricing (today/tomorrow).
You can retrieve both electricity and gas pricing data using this package. With v5.0 we support two official backends:
REST (default)
APIBackend.REST— Public REST API.- Electricity: hourly + quarter-hour. Gas: daily.
- Single date per call;
end_datemust equalstart_dateif provided.
GraphQL (optional)
APIBackend.GRAPHQL— GraphQL endpoint with multi-day ranges and extended metadata (TimeRange, averages).end_dateis required; electricity is always hourly (intervalis ignored).
⚡ Electricity Prices
Electricity prices change every hour. Prices for the next day are typically published between 14:00–15:00.
Common fields (EnergyPrices)
current_price— Current electricity price for the active hour/time rangeaverage_price— Average price over the selected periodextreme_prices— Tuple(min_price, max_price)pct_of_max_price— Current price expressed as % of the maximumprice_at_time(moment)— Look up the price for a specific UTC timestamptimestamp_prices— List of{"timerange": TimeRange, "price": float}entrieshighest_price_time_range/lowest_price_time_range— TimeRange with highest/lowest pricetime_ranges_priced_equal_or_lower— Number of ranges priced ≤ current price
🔥 Gas Prices
Gas prices are fixed for 24 hours, and a new daily rate applies starting at 06:00 each morning.
Common fields (EnergyPrices)
current_price— Current gas price for todayaverage_price— Average price over the requested periodextreme_prices— Tuple(min_price, max_price)price_at_time(moment)— Price lookup for a UTC timestamptimestamp_prices—{"timerange": TimeRange, "price": float}entrieshighest_price_time_range/lowest_price_time_range— TimeRange with highest/lowest pricepct_of_max_price,time_ranges_priced_equal_or_lower— Not applicable for gas prices
Client Methods (REST + GraphQL)
get_electricity_prices()
| Parameter | Type | Description |
|---|---|---|
start_date |
date |
Start of the period (local timezone). |
end_date |
date |
End of the period (local timezone). |
interval |
Interval |
REST only: Interval.QUARTER or Interval.HOUR. Ignored by GraphQL. |
price_type |
PriceType |
Type of price to return. See PriceType for options (default ALL_IN). |
get_gas_prices()
| Parameter | Type | Description |
|---|---|---|
start_date |
date |
Start of the period (local timezone). |
end_date |
date |
End of the period (local timezone). |
price_type |
PriceType |
Type of price to return. See PriceType for options (default ALL_IN). |
PriceType
Specifies the type of prices returned by both backends.
| Value | Description |
|---|---|
MARKET |
Wholesale market price excluding VAT and without additional surcharges (REST base, GraphQL energyPriceExcl) |
MARKET_WITH_VAT |
Market price including VAT but still without surcharges (REST base_with_vat, GraphQL energyPriceIncl) |
ALL_IN_EXCL_VAT |
Market price plus surcharges excluding VAT (REST all_in, GraphQL energyPriceExcl + additionalCosts.priceExcl) |
ALL_IN |
Final consumer rate including VAT and surcharges (REST all_in_with_vat, GraphQL energyPriceIncl + additionalCosts.priceIncl). |
Used in: get_electricity_prices, get_gas_prices
Interval
Specifies the interval for REST API requests:
| Value | Description |
|---|---|
Interval.QUARTER |
15-minute electricity prices |
Interval.HOUR |
Hourly electricity prices |
Interval.DAY |
Daily gas prices |
Contributing
This is an active open-source project. We are always open to people who want to use the code or contribute to it.
We've set up a separate document for our contribution guidelines.
Thank you for being involved! :heart_eyes:
Setting up development environment
The simplest way to begin is by utilizing the Dev Container feature of Visual Studio Code or by opening a CodeSpace directly on GitHub. By clicking the button below you immediately start a Dev Container in Visual Studio Code.
This Python project relies on Poetry as its dependency manager, providing comprehensive management and control over project dependencies.
You need at least:
- Python 3.12+
- Poetry
Installation
Install all packages, including all development requirements:
poetry install
Poetry creates by default an virtual environment where it installs all necessary pip packages.
Prek
This repository uses the prek framework, all changes are linted and tested with each commit. To setup the prek check, run:
poetry run prek install
And to run all checks and tests manually, use the following command:
poetry run prek run --all-files
Testing
It uses pytest as the test framework. To run the tests:
poetry run pytest
To update the syrupy snapshot tests:
poetry run pytest --snapshot-update
Migration
Upgrading from v4.x? See MIGRATION_V5.md for a summary of breaking changes and examples for REST and GraphQL.
License
MIT License
Copyright (c) 2022-2025 Klaas Schoute
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file energyzero-5.0.0.tar.gz.
File metadata
- Download URL: energyzero-5.0.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72f87cfb67fc3e444e5ac3b058b03c776fc408f59b0d80586825cb6de7182bce
|
|
| MD5 |
2b0721101f839ce7230fd80955828013
|
|
| BLAKE2b-256 |
5c1f9a6ac6a61c2a02158f0bcd90c399aa24d002c4a30e499f8467ea6a2bec9e
|
Provenance
The following attestation bundles were made for energyzero-5.0.0.tar.gz:
Publisher:
release.yaml on klaasnicolaas/python-energyzero
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
energyzero-5.0.0.tar.gz -
Subject digest:
72f87cfb67fc3e444e5ac3b058b03c776fc408f59b0d80586825cb6de7182bce - Sigstore transparency entry: 774583076
- Sigstore integration time:
-
Permalink:
klaasnicolaas/python-energyzero@60a2ec9934f4f534de3655b02f9fa9827f129cca -
Branch / Tag:
refs/tags/v5.0.0 - Owner: https://github.com/klaasnicolaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@60a2ec9934f4f534de3655b02f9fa9827f129cca -
Trigger Event:
release
-
Statement type:
File details
Details for the file energyzero-5.0.0-py3-none-any.whl.
File metadata
- Download URL: energyzero-5.0.0-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76685a86ece1894abedcb5745c1c8b1aec7b81d8c3fab00d739c8d4b4674c1ee
|
|
| MD5 |
f7228ee1fd5e2b74d2371036269e568e
|
|
| BLAKE2b-256 |
0a6680ac95b858aeabe7589269bc9e5568b98cd5d75cd2f6eb506a738d0603bb
|
Provenance
The following attestation bundles were made for energyzero-5.0.0-py3-none-any.whl:
Publisher:
release.yaml on klaasnicolaas/python-energyzero
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
energyzero-5.0.0-py3-none-any.whl -
Subject digest:
76685a86ece1894abedcb5745c1c8b1aec7b81d8c3fab00d739c8d4b4674c1ee - Sigstore transparency entry: 774583078
- Sigstore integration time:
-
Permalink:
klaasnicolaas/python-energyzero@60a2ec9934f4f534de3655b02f9fa9827f129cca -
Branch / Tag:
refs/tags/v5.0.0 - Owner: https://github.com/klaasnicolaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@60a2ec9934f4f534de3655b02f9fa9827f129cca -
Trigger Event:
release
-
Statement type: