Energy cost
energy-cost is an open-source Python library that calculates a complete energy bill from metered consumption and injection. It’s what Cofy’s billing module and energy_cost source use, and it also works on its own.
A bill is calculated from a contract, which brings together:
| Part | What it is |
|---|---|
| supplier | The energy supplier’s tariff |
| distributor | The grid operator’s tariff |
| fees | Government fees and levies, such as excise |
| taxes | VAT on each part of the bill |
| timezone | The time zone all dates and times are read in |
You rarely write all of it. Give a contract a region, connection type, customer type and distributor, and energy-cost fills in the distributor’s tariff, the fees, the taxes and the time zone from its built-in data. Then you only write the supplier’s tariff:
region: be_flandersconnection_type: electricitycustomer_type: residentialdistributor_key: fluvius_imewosupplier: - start: 2025-01-01T00:00:00+01:00 consumption: energy: { constant_cost: 95.0 }Where to go next
Section titled “Where to go next”- Contracts: every part of a contract, and how built-in data is filled in.
- Tariffs: how to write a tariff, from a fixed price to time-of-use, tiers and dynamic prices.
- Taxes and capacity: VAT rates and capacity tariffs.
- Built-in data: the regions, distributors, fees and taxes energy-cost knows.
- Examples: complete contracts to start from.
- Using it from Python: calculate a bill in your own code.
energy-cost works in euro, MWh and MW:
| Quantity | Unit |
|---|---|
| Energy prices | €/MWh. 1 c/kWh is 10 €/MWh, so 9.5 c/kWh is 95.0. |
| Fixed costs | € per period, such as € per year |
| Capacity prices | € per MW |
| Tax rates | A fraction: 6% is 0.06 |
| The bill | € |
A positive cost is paid by the customer; a negative cost is received. That holds for injection too: a price you pay for the energy you inject is positive, and a price you receive for it is negative.
Inside Cofy
Section titled “Inside Cofy”- The billing module calculates a bill from meter data and a contract sent with each request.
- The
energy_costsource serves the prices of a tariff through the tariff module, for example your own dynamic tariff.