Calculate business days in Python
Add or count working days with numpy, the holidays package, or the Dierum API.
Option 1: numpy
numpy.busday_offset and numpy.busday_count handle
business-day arithmetic. By default they skip Saturday and Sunday only; pass
holidays explicitly.
import numpy as np
np.busday_offset("2027-03-25", 2, roll="forward")
# numpy.datetime64('2027-03-29') (Sat/Sun skipped, Good Friday not)
np.busday_offset("2027-03-25", 2, roll="forward",
holidays=["2027-03-26"])
# numpy.datetime64('2027-03-30')
The weekmask parameter supports non-standard weekends, e.g.
weekmask="Sun Mon Tue Wed Thu" for Saudi Arabia.
Option 2: the holidays package
pip install holidays. Gives you the holiday dates; combine with
numpy or your own loop for the arithmetic.
import holidays
us = holidays.country_holidays("US", years=2027)
"2027-11-25" in us # True
us.get("2027-11-25") # 'Thanksgiving'
Option 3: Dierum API
One request; holidays, subdivision calendars, market calendars, and per-country weekends are maintained server-side.
import requests
r = requests.get(
"https://dierum.io/v1/add",
params={"region": "XNYS", "start": "2027-03-25", "days": 2},
headers={"X-Api-Key": KEY},
)
r.raise_for_status()
r.json()["result"] # '2027-03-30'
Region codes cover countries (US), subdivisions
(US-CA, DE-BY), and financial markets
(XNYS). See the API reference for counting,
due dates, and pay schedules.
Need this in code? The API answers the same questions over HTTPS with one GET request. Free tier of 100 calls a day, and the playground needs no key at all.