Skip to main content

Official Python SDK for the holidays.rest API

Project description

holidays.rest Python SDK

Codacy Badge Codacy Badge

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

holidays_rest-1.0.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

holidays_rest-1.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

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

Hashes for holidays_rest-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d3e6d268998f1335196b5c6ba4a35f122c530f5839ce8c7fbe3aecbad45db47d
MD5 a66a82a9092a76eaf69c4a40dd1f3f3c
BLAKE2b-256 7eb9d4c63b4326d7ce56f63c75273f059fc2f37f8846354ab3491e66032df4c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for holidays_rest-1.0.0.tar.gz:

Publisher: publish.yml on holidays-rest/sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for holidays_rest-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 499e4671fbe358285d7d3dc8aec5a39334c6bf1155a5d7ae00ad011d81307a5e
MD5 5f09eb126c7bd75809ad4c3b488f7c0c
BLAKE2b-256 c34eee47bdbc2fad793678c971ccbf32ec904dbb0f00b77cf910e6e8fe9fca80

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page