Skip to main content

Energy cost calculation

Project description

Energy cost

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

To use this library, you first specify the Tariff applicable to you in a yaml file. See the examples/tariffs directory for inspiration, with notebooks/tariffs.ipynb for a detailed walkthrough.

A lot of tariffs are based on an Index, which is a price that changes over time based on the market price of energy. We have built in support for fetching these prices from ENTSOE or defining them in a data file, see notebooks/index.ipynb for more info.

Then, you can use the Contract class to calculate your costs based on your consumption data. See notebooks/contract.ipynb for an example.

We already have some built in tariffs for the Belgian market, which you can find in src/energy_cost/data/be/. These are the distributor tariffs for the main Belgian distributors, as well as the government fees and taxes. We plan to expand this to other European countries in the future, feel free to contribute if you want to see your country's tariffs in the library!

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. This means that you can use the library with any timezone, regardless of the timezone of the input data or the tariff definitions. By default, the timezone is set to UTC.

Example usage

First define the tariff from your distributor in a yaml file, for example:

- start: 2024-01-01T00:00:00+01:00
  consumption:
    constant_cost: 100.0
  injection:
    constant_cost: -20.0

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

from energy_cost import Contract, Meter, Tariff
from energy_cost.data.be import distributors, fees, tax_rate

contract = Contract(
    provider=Tariff.from_yaml("../examples/tariffs/fixed.yml"),
    distributor=distributors["fluvius_imewo"],
    fees=[fees["flanders_residential"], fees["be_residential"]],
    tax_rate=tax_rate,
    timezone=ZoneInfo("Europe/Brussels"),
)

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.calculate_cost([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.

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.2.4.tar.gz (37.1 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.2.4-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: energy_cost-0.2.4.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.4.tar.gz
Algorithm Hash digest
SHA256 4a061228c8722dbf27b156ce82d42c052e2796949fa6d043f497d8e06a0742ac
MD5 4d70bb5f8dabc3b62756df325e3b0ab2
BLAKE2b-256 4186be5c607f58275be562359e598f0b191f85bc06d3847253f407fd3b7184a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: energy_cost-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 35.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 39a364269fcde9022863666009ffac5e141d94e33ae49e079d28c5c1579cab9b
MD5 1cb260a38387108e789c6a75da445976
BLAKE2b-256 e7d65c196b5ed879994ebe33fdc0221f25deb97cc6c5cfa87c897040545629ce

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