Skip to main content

Official Python SDK for the holidays.rest API

Project description

holidays.rest Python SDK

Test Publish 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.2.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.2.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file holidays_rest-1.2.0.tar.gz.

File metadata

  • Download URL: holidays_rest-1.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 01c95fe3da80c0305a37aff3057eebc1353e3228a689b4772588fe3f75063640
MD5 bf59e070bc84bf2d13acc60f425e4f09
BLAKE2b-256 a16692fc6a341f3bede69db3546b7aaaccb3f6651281020227523070e2a001bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for holidays_rest-1.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: holidays_rest-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8929ed14e205b5021cbb61ef7caff460a60c7fd4efd1babbb432b2933c391524
MD5 95ce78c3645a80a2857a481cfc5872cd
BLAKE2b-256 26cabe3f42e3b94a638d26a69b745a318e12899928d4966f8fb16d3951731502

See more details on using hashes here.

Provenance

The following attestation bundles were made for holidays_rest-1.2.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