import requests
API_KEY = 'YOUR_API_KEY'
response = requests.get(
'https://api.api-ninjas.com/v1/holidays',
params={'country': 'US', 'year': 2026},
headers={'X-Api-Key': API_KEY},
)
print(response.json())Prerequisites
- Python 3.7+ installed
- The
requestslibrary (pip install requests) - A free API Ninjas API key
Step 1: Get your API key
Sign up at api-ninjas.com/register.
Step 2: Make the API request
import requests
API_KEY = 'YOUR_API_KEY'
response = requests.get(
'https://api.api-ninjas.com/v1/holidays',
params={'country': 'US', 'year': 2026},
headers={'X-Api-Key': API_KEY},
)
print(response.json())Step 3: Use the response
[
{
"country": "United States",
"iso": "US",
"year": 2026,
"date": "2026-01-01",
"day": "Thursday",
"name": "New Year's Day",
"type": "federal_holiday"
},
{
"country": "United States",
"iso": "US",
"year": 2026,
"date": "2026-07-04",
"day": "Saturday",
"name": "Independence Day",
"type": "federal_holiday"
}
]Complete example
import os
import requests
from datetime import date
API_KEY = os.environ['API_NINJAS_KEY']
URL = 'https://api.api-ninjas.com/v1/holidays'
def get_holidays(country: str, year: int, kind: str | None = None) -> list:
params = {'country': country, 'year': year}
if kind:
params['type'] = kind
response = requests.get(
URL,
params=params,
headers={'X-Api-Key': API_KEY},
timeout=10,
)
response.raise_for_status()
return response.json()
if __name__ == '__main__':
holidays = get_holidays('US', 2026)
for h in holidays:
print(f"{h['date']} {h['day']:9} {h['name']}")Finding the next upcoming holidays
from datetime import date
today = date.today()
holidays = get_holidays('US', today.year)
upcoming = [h for h in holidays if date.fromisoformat(h['date']) >= today]
print(f"Next {min(5, len(upcoming))} holidays:")
for h in upcoming[:5]:
print(f" {h['date']} {h['name']}")Filtering by holiday type
Pass a type parameter to get only federal holidays, observances, or seasonal events:
# Filter to a specific holiday type — e.g., federal_holiday, observance, season
federal = get_holidays('US', 2026, kind='federal_holiday')
for h in federal:
print(f"{h['date']} {h['name']}")Holidays across multiple countries
countries = ['US', 'CA', 'GB', 'AU', 'JP']
year = 2026
for country in countries:
holidays = get_holidays(country, year)
print(f"{country}: {len(holidays)} holidays in {year}")Calculating business days
Combine holidays with weekday filtering to count business days in a date range — useful for SLA calculations or invoicing:
from datetime import date, timedelta
def is_business_day(day: date, holiday_dates: set[date]) -> bool:
return day.weekday() < 5 and day not in holiday_dates
holidays = get_holidays('US', 2026)
holiday_dates = {date.fromisoformat(h['date']) for h in holidays}
# Count business days in March 2026
start = date(2026, 3, 1)
end = date(2026, 3, 31)
days = [start + timedelta(d) for d in range((end - start).days + 1)]
business_days = sum(1 for d in days if is_business_day(d, holiday_dates))
print(f"Business days in March 2026: {business_days}")Related APIs
For workday and bank-closure questions use Working Days. For exchange-specific schedules see Stock Exchange (includes stockexchangeholidays).