bizdays computes business days with holiday calendars. This README covers
bizdays 2.0, which runs on Python 3.10 to 3.14 with NumPy 1.24 or newer and
pandas 2 or 3. bizdays.Calendar accepts single dates, Python sequences,
NumPy arrays and pandas date-like inputs, and returns NumPy scalars or arrays.
pip install bizdaysInstall the optional integrations with:
pip install "bizdays[pmc]"
pip install "bizdays[xcal]"
pip install "bizdays[work]">>> from bizdays import Calendar
>>> cal = Calendar.load(name="ANBIMA")
>>> cal.bizdays("2014-01-13", "2015-01-13")
np.float64(253.0)
>>> cal.following("2015-12-25")
np.datetime64('2015-12-28')
>>> cal.offset(["2014-01-02", "2014-01-03"], [1, 5])
array(['2014-01-03', '2014-01-10'], dtype='datetime64[D]')
>>> cal.seq("2014-01-02", "2014-01-07")
array(['2014-01-02', '2014-01-03', '2014-01-06', '2014-01-07'],
dtype='datetime64[D]')
>>> cal.getdate("15th day", "2002-05")
np.datetime64('2002-05-15')
>>> cal.getbizdays(2024)
np.float64(253.0)ANBIMA: 2000-01-01 to 2099-12-25. Official ANBIMA holidays up to 2079; later years are projected with the national holiday rule.B3: official B3 holidays for 2000-2026. Years 2027-2099 are projected: ANBIMA holidays, plus December 24, plus the last weekday of the year. Projected years are replaced when B3 publishes them.Actual: no holidays, every day is a business day; 1900-01-01 to 2199-12-31.
You can list them with list_calendars():
>>> from bizdays import list_calendars
>>> list_calendars()["packaged"]
['ANBIMA', 'B3', 'Actual']Use Calendar.load(name="...") for packaged calendars and
Calendar.load(filename="...") for custom JSON calendar files.
External providers are also available through prefixed names:
Calendar.load(name="PMC/<calendar>")forpandas_market_calendarsCalendar.load(name="XCAL/<calendar>")forexchange_calendarsCalendar.load(name="WORK/<code>")forworkalendar
>>> custom = Calendar(
... holidays=["2024-01-01", "2024-12-25"],
... weekdays=["Saturday", "Sunday"],
... startdate="2024-01-01",
... enddate="2024-12-31",
... name="Example",
... )
>>> custom.bizdays("2024-12-20", "2024-12-31")
np.float64(6.0)Calendar.load(filename="...") expects a JSON object with these fields:
name: stringweekdays: list of weekday namesholidays: list of ISO date stringsfinancial: booleanstart.dateandend.date: optional ISO date strings (YYYY-MM-DD) that setstartdateandenddate; a bad value raisesValueErroradjust.fromandadjust.to: optional; only the defaults"following"and"preceding"are accepted, and other values raiseValueError
Example:
{
"name": "Custom",
"weekdays": ["saturday", "sunday"],
"holidays": ["2024-01-01", "2024-12-25"],
"financial": true,
"start.date": "2024-01-01",
"end.date": "2024-12-31"
}- packaged calendars:
ANBIMA,B3, andActual PMC/...names require the optionalbizdays[pmc]extraXCAL/...names require the optionalbizdays[xcal]extraWORK/...names require the optionalbizdays[work]extraCalendarmethods return NumPy values such asnumpy.datetime64,numpy.float64counts (NaNfor missing),numpy.ndarray, and masked arrays forisbizdayvectors (fill_value=False)- results are positional NumPy values: assign them to a DataFrame column, and
give
index=if you wrap them in a pandas Series; see the API reference - pandas timestamps, indexes, and series can be passed directly to the public API