Skip to main content

Energy cost calculation

Project description

Energy cost

Python package to model your energy bill based on your energy consumption.

This energy bill is calculated based on a Contract or even a ContractHistory, which is a collection of contracts that can change over time. A contract consists of 5 parts:

  • supplier: the Tariff of your energy supplier
  • distributor: the Tariff of your energy distributor
  • fees: the government fees applicable to you, als defined as a Tariff
  • taxes: the government Taxes applicable to each cost component of your bill
  • timezone: the timezone in which all calculations will be done

You can also specify a region, connection_type, customer_type and distributor_key in your contract, which will automatically fetch the applicable distributor tariffs, fees, taxes and timezone for you from our built in data. If your region is not yet supported, you can contribute the data for your region, see CONTRIBUTING.md for how to do that.

Contracts can be defined in a yaml file, which makes it easy to manage and update your contract over time. See notebooks/contract.ipynb for more info on how to define your contract in a yaml file.

We also have more detailed documentation on the different components of a contract, see notebooks for all available notebooks. You can find example yaml files for tariffs and taxes in the examples directory.

A lot of tariffs are based on an Index, which is a price that changes over time based on the market price of energy, see notebooks/index.ipynb for more info.

Note on units: all consumption based costs are in €/MWh, all energy values are in MWh. All monetary values are in €.

Note on timezones: every method that takes timestamps as input also takes a timezone as input. All timestamps will be aligned to this timezone, and all outputs will be in this timezone as well. By default, the timezone is set by the regional data, but you can override it in your contract if needed.

Example usage

You can define your contract in a yaml file like this:

supplier:
- start: 2025-01-01T00:00:00+01:00
  consumption:
    constant_cost: 90.0
region: be_flanders
connection_type: electricity
customer_type: residential
distributor_key: fluvius_imewo

Then, you can use the Contract class to calculate your costs based on your consumption data:

from energy_cost import Contract, Meter
import pandas as pd

Contract.from_yaml("../examples/contracts/inline.yml")

consumption = Meter(
    data=pd.DataFrame(
        {
            "timestamp": pd.date_range("2024-01-01T00:00:00+01:00", "2024-03-01T00:00:00+01:00", freq="15min"),
            "value": 0.0002,
        }
    )
)

contract.apply([consumption])

For more detailed examples, see the notebooks in the notebooks directory.

Development

Prerequisites

  • Python 3.12+
  • uv (fast Python package manager)

1. Install dependencies

uv sync
uv tool install poethepoet

2. Notebooks

You can easilly test the project using our notebooks. They are located in the notebooks directory and can be run with:

poe notebooks

Some notebooks make use of external APIs and require API keys. You can set these in a .env file in the root of the project, using the .env.example file as a template.

If you add new features, please add a new notebook to demonstrate them.

3. Run tests

poe test

4. Code quality (pre-commit)

Pre-commit hooks are configured out of the box. Install them once:

pre-commit install

Every commit will automatically run:

Tool Task Command
Ruff Linting + auto-fix poe lint
Ruff Formatting poe format
ty Type checking poe check

You can also run them manually at any time.

Contributing

Contributions are welcome! See CONTRIBUTING.md for how to get started, including how to add support for new regions.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

energy_cost-0.4.1.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

energy_cost-0.4.1-py3-none-any.whl (56.9 kB view details)

Uploaded Python 3

File details

Details for the file energy_cost-0.4.1.tar.gz.

File metadata

  • Download URL: energy_cost-0.4.1.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for energy_cost-0.4.1.tar.gz
Algorithm Hash digest
SHA256 f0d85b76898af664a1bc90a5927f223fd9f5cf67e2e0ef9bd216d00fc4fa604b
MD5 ff6975b7424f87fa3bcaf6f9e11c5074
BLAKE2b-256 3a524e8478e42b2a61f21af2c30fc174e5b6d20e5cb9249fa46c0acf39f0d025

See more details on using hashes here.

File details

Details for the file energy_cost-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: energy_cost-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 56.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for energy_cost-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87707161560b07cb1f6031f726558f84dc20b8e2dd71e17a608847c0192c2392
MD5 ce59ef78f2dad903c087795994c43111
BLAKE2b-256 299ba31e771c8b160f0db14f759a95205e62456e234d115a89aafe88f06f67dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page