Hong Kong public holidays from GovHK open data, with algorithmic fallback for historical and far-future years.
Project description
hongkong_holiday
Hong Kong public holidays from official GovHK open data, with an algorithmic fallback for historical and far-future years.
Why this package?
The official 1823 GovHK feed is authoritative — it reflects the actual gazetted
general holidays, including one-off substitutions — but it only covers roughly a
two-year window (the current year and the next). hongkong_holiday combines:
- Primary — GovHK API (cached in memory): authoritative data from
https://www.1823.gov.hk/common/ical/{en,tc,sc}.json, fetched lazily once per instance with retries. - Fallback — algorithmic estimation: for years outside the API window,
dates are computed with the well-maintained
holidayspackage, and every Sunday is treated as a general holiday per Hong Kong's General Holidays Ordinance (Cap. 149).
Every result is tagged with its source ("govhk" or "estimated") so you
always know whether you are looking at gazetted or computed data.
Installation
pip install hongkong_holiday
Quick start
from hongkong_holiday import HKHolidays
hk = HKHolidays(lang="en") # "en", "tc" (繁體) or "sc" (简体)
# Is a given date a holiday?
hk.is_holiday("2026-07-01") # True — HKSAR Establishment Day
hk.is_holiday("2026-07-05") # True — Sunday (general holiday)
hk.is_public_holiday("2026-07-05") # False — plain Sunday, not gazetted
hk.holiday_name("2026-12-25") # "Christmas Day"
# Historical year (outside the API window) — automatic fallback:
hk.is_public_holiday("2020-07-01") # True, computed by the fallback provider
# Describe a single date (weekday: Sunday=0, Monday=1 ... Saturday=6)
info = hk.get_date("2026-07-05")
# DateInfo(date=datetime.date(2026, 7, 5), weekday=0,
# is_holiday=True, holiday_name='Sunday')
# Describe every day of a year
for day in hk.get_dates(2026):
print(day.date, day.weekday, day.is_holiday, day.holiday_name)
# List just the holidays of a year
for holiday in hk.get_holidays(2026):
print(holiday.date, holiday.name, holiday.source)
# Next upcoming holiday
print(hk.next_holiday()) # e.g. 2026-09-26 The day following ...
Counting Saturdays and Sundays as holidays
Every query method takes include_sundays / include_saturdays flags.
Sundays are general holidays under Hong Kong law, so is_holiday,
holiday_name, get_date and get_dates include them by default;
Saturdays are opt-in for organisations on a 5-day week:
hk.is_holiday("2026-07-04") # False (a Saturday)
hk.is_holiday("2026-07-04", include_saturdays=True) # True
hk.is_holiday("2026-07-05", include_sundays=False) # False (named holidays only)
# Year listing with weekends included
hk.get_holidays(2026, include_sundays=True, include_saturdays=True)
# Full-year calendar treating Saturday + Sunday as non-working days
days_off = [d for d in hk.get_dates(2026, include_saturdays=True) if d.is_holiday]
Export to CSV
from hongkong_holiday import HKHolidays, export_csv
hk = HKHolidays(lang="tc")
export_csv(hk.get_holidays(2026), "hk_holidays_2026.csv")
# Written as UTF-8 with BOM so Chinese names open correctly in Excel.
API overview
| Member | Description |
|---|---|
HKHolidays(lang="en", timeout=10.0, retries=3, use_fallback=True) |
Main entry point. |
is_holiday(date, include_sundays=True, include_saturdays=False) |
True for a general holiday — named holidays and (by default) Sundays. |
is_public_holiday(date, include_sundays=False, include_saturdays=False) |
True for gazetted/named holidays; weekends only when flagged. |
holiday_name(date, include_sundays=True, include_saturdays=False) |
Holiday name, "Sunday"/"Saturday" for flagged weekend days, else None. |
get_holiday(date, include_sundays=False, include_saturdays=False) |
The Holiday object on that date, or None. |
get_holidays(year, include_sundays=False, include_saturdays=False) |
Sorted list of Holiday objects for a year. |
get_date(date, include_sundays=True, include_saturdays=False) |
A DateInfo — date, weekday (Sun=0, Mon=1 … Sat=6), is_holiday, holiday_name. |
get_dates(year, include_sundays=True, include_saturdays=False) |
A DateInfo for every day of the year, in order. |
next_holiday(date=None, include_sundays=False, include_saturdays=False) |
Next holiday after the given date (default today). |
api_years |
Years currently covered by the live GovHK feed. |
refresh() |
Discard the in-memory cache and re-fetch on next query. |
export_csv(holidays, path) |
Write holidays to a CSV file. |
weekday_number(date) |
Sunday-first weekday number: Sunday=0, Monday=1 … Saturday=6. |
date arguments accept datetime.date, datetime.datetime, ISO strings
("2026-07-01") and compact iCal strings ("20260701").
Note on weekday numbering:
DateInfo.weekdayandweekday_number()use Sunday=0, Monday=1 … Saturday=6 — this differs from Python'sdate.weekday()(Monday=0) anddate.isoweekday()(Monday=1, Sunday=7).
Behaviour details
- Caching: the feed is downloaded at most once per
HKHolidaysinstance and kept in memory. Long-running services should callrefresh()periodically (e.g. daily) to pick up newly gazetted holidays. - Offline resilience: if the feed cannot be reached, the module logs a
warning and serves all years from the fallback provider instead of
failing (set
use_fallback=Falseto fail loudly instead). - Estimated data caveat: lunar-calendar holidays and one-off government
substitutions in
"estimated"results may differ from what is eventually gazetted. Treat far-future estimates as provisional.
Development
git clone https://github.com/funglkf00/hongkong_holiday
cd hongkong_holiday
pip install -e .[dev]
pytest
The test suite is fully offline — the GovHK feed is mocked.
Publishing to PyPI
pip install build twine
python -m build
twine upload dist/*
License
MIT. Holiday data © HKSAR Government, provided via DATA.GOV.HK under its terms of use.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hongkong_holiday-1.0.0.tar.gz.
File metadata
- Download URL: hongkong_holiday-1.0.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d4dd1db4c10c54d9e3cb79cd9daac63c1bf148934d7308384ec3284cb36e608
|
|
| MD5 |
d96d21ef6c7ffe2a9bce7f3ff946c9ed
|
|
| BLAKE2b-256 |
5372fb7d094163f147f4a03fc937996ee087865a4a2ee01d55dcbdca9bc25165
|
File details
Details for the file hongkong_holiday-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hongkong_holiday-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4d349dfc46e99fdd6394b4a6533b72ac320d59c62f6b0630f8fb4efe3b6d237
|
|
| MD5 |
8ca68e4150f4973a072bd5c6ef5f5108
|
|
| BLAKE2b-256 |
7382d5ed243ca6e0c6595c2fac44251ac106f85853b3d2ebba11aa26df01b2ea
|