Official Python SDK for the holidays.rest API
Project description
holidays.rest Python SDK
Official Python SDK for the holidays.rest API.
Requirements
- Python 3.10+
httpx(only dependency)
Installation
pip install holidays-rest
Quick Start
from holidays_rest import HolidaysClient
with HolidaysClient(api_key="YOUR_API_KEY") as client:
holidays = client.holidays(country="US", year=2024)
for h in holidays:
print(h.date, h.name.get("en"))
Get an API key at holidays.rest/dashboard.
API
HolidaysClient (sync)
from holidays_rest import HolidaysClient
client = HolidaysClient(
api_key="YOUR_API_KEY", # required
timeout=15.0, # optional, default 15s
)
Supports use as a context manager (with statement) to close the underlying connection pool on exit.
AsyncHolidaysClient (async)
from holidays_rest import AsyncHolidaysClient
async with AsyncHolidaysClient(api_key="YOUR_API_KEY") as client:
holidays = await client.holidays(country="US", year=2024)
Both clients expose identical methods — only the async/await syntax differs.
client.holidays(...) → list[Holiday]
| Parameter | Type | Required | Description |
|---|---|---|---|
country |
str |
yes | ISO 3166 alpha-2 code (e.g. "US") |
year |
int | str |
yes | Four-digit year (e.g. 2024) |
month |
int | str |
no | Month filter (1–12) |
day |
int | str |
no | Day filter (1–31) |
type |
str | list[str] |
no | "religious", "national", "local" |
religion |
int | list[int] |
no | Religion code(s) 1–11 |
region |
str | list[str] |
no | Subdivision code(s) — from country() |
lang |
str | list[str] |
no | Language code(s) — from languages() |
response |
str |
no | "json" (default) | "xml" | "yaml" | "csv" |
# All US holidays in 2024
client.holidays(country="US", year=2024)
# National holidays only
client.holidays(country="DE", year=2024, type="national")
# Multiple types
client.holidays(country="TR", year=2024, type=["national", "religious"])
# Filter by month and day
client.holidays(country="GB", year=2024, month=12, day=25)
# Specific region
client.holidays(country="US", year=2024, region="US-CA")
# Multiple regions
client.holidays(country="US", year=2024, region=["US-CA", "US-NY"])
client.countries() → list[Country]
countries = client.countries()
for c in countries:
print(c.alpha2, c.name)
client.country(country_code) → Country
Returns country details including subdivision codes usable as region filters.
us = client.country("US")
for s in us.subdivisions:
print(s.code, s.name)
client.languages() → list[Language]
langs = client.languages()
Models
All responses are deserialized into dataclasses.
@dataclass
class Holiday:
country_code: str # e.g. "DE"
country_name: str # e.g. "Germany"
date: str # "YYYY-MM-DD"
name: dict[str, str] # {"en": "New Year's Day", "de": "Neujahr", ...}
is_national: bool
is_religious: bool
is_local: bool
is_estimate: bool # True when the date is algorithmically estimated
day: DayInfo # day-of-week, actual vs observed
religion: str # e.g. "Christianity", empty string if not applicable
regions: list[str] # subdivision codes, e.g. ["BW", "BY"]
@dataclass
class DayInfo:
actual: str # day the holiday falls on, e.g. "Thursday"
observed: str # day it is observed (may differ for weekend holidays)
@dataclass
class Country:
name: str
alpha2: str
subdivisions: list[Subdivision]
@dataclass
class Subdivision:
code: str
name: str
@dataclass
class Language:
code: str
name: str
Error Handling
Non-2xx responses raise HolidaysApiError:
from holidays_rest import HolidaysClient, HolidaysApiError
with HolidaysClient(api_key="YOUR_API_KEY") as client:
try:
holidays = client.holidays(country="US", year=2024)
except HolidaysApiError as e:
print(e.status_code) # HTTP status code
print(str(e)) # Error message
print(e.body) # Raw response bytes
| Status | Meaning |
|---|---|
| 400 | Bad request |
| 401 | Invalid API key |
| 404 | Not found |
| 500 | Server error |
| 503 | Service unavailable |
License
MIT
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 holidays_rest-1.0.0.tar.gz.
File metadata
- Download URL: holidays_rest-1.0.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3e6d268998f1335196b5c6ba4a35f122c530f5839ce8c7fbe3aecbad45db47d
|
|
| MD5 |
a66a82a9092a76eaf69c4a40dd1f3f3c
|
|
| BLAKE2b-256 |
7eb9d4c63b4326d7ce56f63c75273f059fc2f37f8846354ab3491e66032df4c0
|
Provenance
The following attestation bundles were made for holidays_rest-1.0.0.tar.gz:
Publisher:
publish.yml on holidays-rest/sdk-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
holidays_rest-1.0.0.tar.gz -
Subject digest:
d3e6d268998f1335196b5c6ba4a35f122c530f5839ce8c7fbe3aecbad45db47d - Sigstore transparency entry: 1315284382
- Sigstore integration time:
-
Permalink:
holidays-rest/sdk-py@11966fa9f891421547c54e0ff5a7ae906f14b75c -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/holidays-rest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@11966fa9f891421547c54e0ff5a7ae906f14b75c -
Trigger Event:
release
-
Statement type:
File details
Details for the file holidays_rest-1.0.0-py3-none-any.whl.
File metadata
- Download URL: holidays_rest-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
499e4671fbe358285d7d3dc8aec5a39334c6bf1155a5d7ae00ad011d81307a5e
|
|
| MD5 |
5f09eb126c7bd75809ad4c3b488f7c0c
|
|
| BLAKE2b-256 |
c34eee47bdbc2fad793678c971ccbf32ec904dbb0f00b77cf910e6e8fe9fca80
|
Provenance
The following attestation bundles were made for holidays_rest-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on holidays-rest/sdk-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
holidays_rest-1.0.0-py3-none-any.whl -
Subject digest:
499e4671fbe358285d7d3dc8aec5a39334c6bf1155a5d7ae00ad011d81307a5e - Sigstore transparency entry: 1315284500
- Sigstore integration time:
-
Permalink:
holidays-rest/sdk-py@11966fa9f891421547c54e0ff5a7ae906f14b75c -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/holidays-rest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@11966fa9f891421547c54e0ff5a7ae906f14b75c -
Trigger Event:
release
-
Statement type: