Skip to main content

bdew_datetimes

GitHub Workflow StatusPyPI - Python VersionPyPI - LicensePyPI

A collection of utils to work with datetimes and holidays in the German energy market and is based on the python-holiday package.

The implementation considers the publications of the BDEW (Bundesverband der Energie- und Wasserwirtschaft e. V.) and EDI@Energy, which provide boundaries and guidance for the data exchange on the german energy market.

Current highlights:

  • BDEW-holiday calendar
    • allows dict like evaluation of dates and datetimes and contains all holidays considered by the BDEW
  • Statutory Periods ("Gesetzliche Fristen")
    • calculate dates of the kind "x Werktage ab Stichtag"
    • calculate dates of the kind "nter Werktag des Fristen- bzw. Liefermonats"
  • Gas-Day / Market Day evaluation

Future Scope:

  • providing subdivision holiday calendars to allow granular load profiles

Quick Start and Examples

Install the package from pypi:

pip install bdew-datetimes

Check if a date is a specific BDEW Holidays

The HolidaySum returned by create_bdew_calendar contains the BDEW specific holidays. This means it contains those holidays which are defined by BDEW which includes Heiligabend and Silvester as well as special days without Marktkommunikation but not the local or nationwide holidays in Germany and its states.

from datetime import date
from bdew_datetimes import create_bdew_calendar

bdew_holidays = create_bdew_calendar()  # this behaves like a dict

assert date(2022, 12, 31) in bdew_holidays # Silvester is a BDEW holiday
assert date(2022, 8, 8) in bdew_holidays is False # Augsburger Friedensfest is _not_ a BDEW holiday (but a holiday in Augsburg only)
assert date(2022, 12, 2) in bdew_holidays is False # The 12th of February is not a BDEW holiday

print(bdew_holidays.get('2022-01-01'))  # prints "Neujahr"

The union (type HolidaySum) of both nation and state wide holidays and the BDEW holidays (only the latter is returned by create_bdew_calendar) is the relevant calendar for German utilities.

Check if a given Date is a BDEW Working Day

BDEW working days are those days taken into account for the "Fristenberechnung". The function is_bdew_working_day considers both national and state wide holidays and BDEW holidays:

from datetime import date

from bdew_datetimes import is_bdew_working_day

assert is_bdew_working_day(date(2023, 1, 1)) is False  # Neujahr (national holiday)
assert is_bdew_working_day(date(2023, 1, 2)) is True  # regular weekday
assert is_bdew_working_day(date(2023, 1, 6)) is False  # Heilige Drei Könige (local holiday in parts of Germany)
assert is_bdew_working_day(date(2023, 4, 7)) is False  # Karfreitag (national holiday, but based on an astronomical calendar)
assert is_bdew_working_day(date(2023, 12, 24)) is False  # Heiligabend (BDEW holiday)

You can also get the next or previous working day for any date:

from datetime import date

from bdew_datetimes import get_next_working_day, get_previous_working_day

assert get_next_working_day(date(2023, 1, 1)) == date(2023, 1, 2)  # the next working day after Neujahr
assert get_previous_working_day(date(2023, 1, 1)) == date(2022, 12, 30)  # the last working day of 2022
assert get_next_working_day(date(2023, 1, 20)) == date(2023, 1, 23)  # the next working day after a friday is the next monday

Calculate Statutory Periods

Statutory periods define the maximum time between e.g. the EDIFACT message for the "Anmeldung" and the actual start of supply ("Lieferbeginn").

from datetime import date

from bdew_datetimes import add_frist
from bdew_datetimes import Period
from bdew_datetimes.enums import DayType, EndDateType

# Eingang der Anmeldung des LFN erfolgt am 04.07.2016. Der Mindestzeitraum von zehn WT
# beginnt am 05.07.2016 und endet am 18.07.2016. Frühestes zulässiges Anmeldedatum
# ist damit der 19.07.2016, sodass die Marktlokation dem LFN frühestens zum Beginn
# des vorgenannten Tages zugeordnet wird.
eingang_der_anmeldung = date(2016, 7, 4)
gesetzliche_frist = Period(
  10,
  DayType.WORKING_DAY,
  end_date_type=EndDateType.EXCLUSIVE
  # lieferbeginn is the exclusive end of the previous supply contract
)
fruehest_moeglicher_lieferbeginn = add_frist(eingang_der_anmeldung, gesetzliche_frist)
assert fruehest_moeglicher_lieferbeginn == date(2016, 7, 19)

Calculate "Liefer- and Fristenmonate"

Liefer- and Fristenmonat are concepts used in MaBiS and GPKE:

from datetime import date

from bdew_datetimes import get_nth_working_day_of_month
from bdew_datetimes.enums import MonthType

# returns the 18th working day of the current month in Germany
get_nth_working_day_of_month(18)

# the 18th working day of November 2023
assert get_nth_working_day_of_month(18, start=date(2023, 11, 1)) == date(2023, 11, 28)

# the 42th working day of Fristenmonat July 2023
assert get_nth_working_day_of_month(42, month_type=MonthType.FRISTENMONAT, start=date(2023, 7, 1)) == date(2023, 9, 29)

Notes

The BDEW considers all days as holidays, which are nationwide holidays and days, which are a holiday in at least one state. Furthermore, the 24. and the 31. December are holidays as well. Therefore, this package utilizes the composition of all available german holiday calendars and adds the two additional days.

Shifting holidays to the next weekday if they fall on a weekend is currently not considered.

Development

This project uses uv for dependency management & tooling and a GNU Makefile to standardize common development commands. If you want to avoid make you can run each command manually, in this case please still refer to the Makefile.

After installing uv & make, set up the development environment with:

make dev

Run the tests and the individual tooling via the corresponding target:

make tests

make typing

make lint

make format

make spell-check

Development

This project uses uv for dependency management and tooling. After installing uv, set up the development environment with:

uv sync --group dev

Run the tests and the individual tooling via the corresponding dependency groups:

uv run --group tests pytest
uv run --group type_check mypy --strict src/bdew_datetimes tests
uv run --group linting ruff check .
uv run --group linting ruff format .
uv run --group spell_check codespell --ignore-words=domain-specific-terms.txt src/bdew_datetimes README.md

License

This library is licensed under the MIT license, see the LICENSE file.

Users

This library is used by the following projects:

Metadata

Release files for bdew_datetimes 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bdew_datetimes 0.12.0
File Size Uploaded Provenance
bdew_datetimes-0.12.0.tar.gz 47.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bdew_datetimes 0.12.0
File Interpreter ABI Platform
bdew_datetimes-0.12.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.1 kB

Release files / bdew_datetimes-0.12.0.tar.gz

Download URL bdew_datetimes-0.12.0.tar.gz
Size 47.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d44cef53b826add289fd956ecabc2ab61d44892c65adb4337800a1a8e662a0b7
BLAKE2b-256 checksum
How to use checksums
adc63ddca74b30b27dcd3d581a5a5f9dd2067e2b60498ee3eb073301271eca05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}

Release files / bdew_datetimes-0.12.0-py3-none-any.whl

Download URL bdew_datetimes-0.12.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edf993d38dce69753becc626b7441cfacd3878bffbcd94fcbb19fef823a2ccc9
BLAKE2b-256 checksum
How to use checksums
93129b31d13bf25ec7593a278eb064018ed512a7b9cce321b643a05511e675c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}

Security for bdew_datetimes 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page