This library loads the official list of bank holidays in the United Kingdom as supplied by GOV.UK. GOV.UK tend to provide this list for only a year or two into the future.
A cached backup list of known bank holidays is stored in this package though it is not updated often. GOV.UK no longer provide bank holidays for some of the older years still part of this backup list.
Install using pip install govuk-bank-holidays
. Sample usage:
from govuk_bank_holidays.bank_holidays import BankHolidays
bank_holidays = BankHolidays()
for bank_holiday in bank_holidays.get_holidays():
print(bank_holiday['title'], 'is on', bank_holiday['date'])
print(bank_holidays.get_next_holiday())
# see govuk_bank_holidays/bank_holidays.py source file for more methods and argument details…
# choose a different locale for holiday titles and notes
bank_holidays = BankHolidays(locale='cy')
# use cached holidays if internet connection is not desired
bank_holidays = BankHolidays(use_cached_holidays=True)
Bank holidays differ around the UK. The GOV.UK source currently lists these for 3 "divisions":
… and many methods in this library take a division
parameter (see constants defined on BankHolidays
class).
NB: If no division is specified, only holidays common to all divisions are returned so some local bank holidays may not be listed. Therefore specifying a division is recommended.
While localisation is provided in English (the default with locale code 'en') and Welsh (locale code 'cy'), please note that the Welsh version may contain errors.
Please report bugs and open pull requests on GitHub.
To work on changes to this library, it’s recommended to install it in editable mode into a virtual environment,
i.e. pip install --editable .
Update cached bank holidays from GOV.UK using python scripts/update-cache.py
.
Update translation files using python scripts/messages.py update
, e.g. when updating the i18n module or when adding new languages.
Compile them using python scripts/messages.py compile
; this is required before testing and distribution.
Updating and compiling translation files requires the gettext system package to be installed.
Use python -m tests
to run all tests locally.
Alternatively, you can use tox
if you have multiple python versions.
[Only for GitHub team members] Distribute a new version to PyPI by:
VERSION
tuple in govuk_bank_holidays/__init__.py
python scripts/messages.py compile; python -m build; twine upload dist/*
locallyBankHolidays
class has a new ALL_DIVISIONS
constant.Copyright (C) 2023 HM Government (Ministry of Justice Digital & Technology). See LICENSE.txt for further details.