Skip to content

klaasnicolaas/python-energyzero

Repository files navigation

alt Header of the EnergyZero package

GitHub Release Python Versions Project Stage Project Maintenance License

GitHub Activity PyPi Downloads GitHub Last Commit Open in Dev Containers

Build Status Typing Status Code Coverage

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 date
from energyzero import EnergyZero, VatOption


async def main() -> None:
    """Show example on fetching the energy prices from EnergyZero."""
    async with EnergyZero(vat=VatOption.INCLUDE) as client:
        start_date = date(2022, 12, 7)
        end_date = date(2022, 12, 7)

        energy = await client.get_electricity_prices(start_date, end_date)
        gas = await client.get_gas_prices(start_date, end_date)


if __name__ == "__main__":
    asyncio.run(main())

More examples can be found in the examples folder.

Data

Note: Currently tested primarily with day-ahead pricing (today/tomorrow).

You can retrieve both electricity and gas pricing data using this package. Each data type supports a set of common fields, with some additional properties depending on whether you use the GraphQL or legacy REST endpoint.

⚑ Electricity Prices

Electricity prices change every hour. Prices for the next day are typically published between 14:00–15:00.

Common fields (Electricity and EnergyPrices)

  • current_price β€” Current electricity price for the current hour or time range
  • average_price β€” Average price over the selected period
  • extreme_prices β€” Tuple of (min_price, max_price)
  • pct_of_max_price β€” Current price as a percentage of the maximum
  • price_at_time(moment) β€” Get price for a specific datetime
  • timestamp_prices β€” List of hourly price entries:
    • REST: {"timestamp": datetime, "price": float}
    • GraphQL: {"timerange": TimeRange, "price": float}

GraphQL-only (get_electricity_prices())

  • highest_price_time_range β€” TimeRange where the price is highest
  • lowest_price_time_range β€” TimeRange where the price is lowest
  • time_ranges_priced_equal_or_lower β€” Count of hours where the price is less than or equal to the current

REST-only (get_electricity_prices_legacy())

  • highest_price_time β€” Timestamp of the highest hourly price
  • lowest_price_time β€” Timestamp of the lowest hourly price
  • hours_priced_equal_or_lower β€” Count of hours with a price ≀ 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 (Gas and EnergyPrices)

  • current_price β€” Current gas price for today
  • average_price β€” Average gas price over the selected period
  • extreme_prices β€” Tuple of (min_price, max_price)
  • price_at_time(moment) β€” Get price for a specific datetime
  • timestamp_prices β€” List of daily price entries:
    • REST: {"timestamp": datetime, "price": float}
    • GraphQL: {"timerange": TimeRange, "price": float}

GraphQL-only (get_gas_prices())

  • highest_price_time_range β€” Time range with the highest daily price
  • lowest_price_time_range β€” Time range with the lowest daily price
  • pct_of_max_price β€” Current price as a percentage of the maximum
  • time_ranges_priced_equal_or_lower β€” Count of days with a price ≀ current price

Function Parameters

Class Parameters

Parameter Type Description Used by
vat VatOption (default: INCLUDE) Include or exclude VAT at class level. get_electricity_prices_legacy, get_gas_prices_legacy

Interval Values

Value Meaning
4 Day
5 Month
6 Year
9 Week

Modern GraphQL Methods

get_electricity_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: ALL_IN or MARKET.

⚠️ This method does not use the class-level vat setting.


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: ALL_IN or MARKET.

⚠️ This method does not use the class-level vat setting.


Legacy REST Methods

get_electricity_prices_legacy()

Parameter Type Description
start_date date Start of the period (local timezone).
end_date date End of the period (local timezone).
interval int Data interval (see interval values table).
vat VatOption | None VAT inclusion (fallback to class setting if None).

get_gas_prices_legacy()

Parameter Type Description
start_date date Start of the period (local timezone).
end_date date End of the period (local timezone).
interval int Data interval (see interval values table).
vat VatOption | None VAT inclusion (fallback to class setting if None).

Enum Options

VatOption

Defines whether prices returned by legacy methods should include VAT.

Value Description
INCLUDE Return prices including VAT
EXCLUDE Return prices excluding VAT

Used in: get_electricity_prices_legacy, get_gas_prices_legacy

πŸ“ Ignored in GraphQL methods (get_electricity_prices, get_gas_prices)


PriceType

Specifies the type of prices returned by GraphQL methods.

Value Description
MARKET Raw wholesale market price (excludes tax, VAT, and purchasing costs)
ALL_IN Final consumer price (includes energy tax, VAT, and purchase fees)

Used in: get_electricity_prices, get_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! 😍

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.

Open in Dev Containers

This Python project relies on Poetry as its dependency manager, providing comprehensive management and control over project dependencies.

You need at least:

Installation

Install all packages, including all development requirements:

poetry install

Poetry creates by default an virtual environment where it installs all necessary pip packages.

Pre-commit

This repository uses the pre-commit framework, all changes are linted and tested with each commit. To setup the pre-commit check, run:

poetry run pre-commit install

And to run all checks and tests manually, use the following command:

poetry run pre-commit 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

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.