Install & Compatibility
Where this runs
tested against v1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
networkdays
✓ from workdays import networkdays
This quickstart demonstrates how to use the `networkdays` function to calculate the number of working days between two dates, accounting for a list of specified holidays. All date inputs must be `datetime.date` objects.
from datetime import date
from workdays import networkdays
# Define start and end dates as datetime.date objects
start_date = date(2023, 1, 1)
end_date = date(2023, 1, 31)
# Define a list of holidays, also as datetime.date objects
holidays = [
date(2023, 1, 1), # New Year's Day
date(2023, 1, 16) # MLK Day
]
# Calculate network days (excluding weekends and specified holidays)
num_workdays = networkdays(start_date, end_date, holidays)
print(f"Number of network days between {start_date} and {end_date}: {num_workdays}")
# You can also specify custom weekend days (1=Monday, 7=Sunday, ISO weekday)
# For example, to make Friday, Saturday, Sunday weekends (5, 6, 7):
# num_workdays_custom_weekend = networkdays(start_date, end_date, holidays, weekend_days=[5, 6, 7])
# print(f"Network days with custom weekends (Fri, Sat, Sun off): {num_workdays_custom_weekend}")
Errors
Common errors & fixes
TypeError: 'str' object cannot be interpreted as a date
You are passing a date string directly to `networkdays` or within the `holidays` list instead of a `datetime.date` object.
fixConvert date strings to `datetime.date` objects using `datetime.strptime('YYYY-MM-DD', '%Y-%m-%d').date()` or `date(year, month, day)`. TypeError: 'datetime.datetime' object is not iterable
You are passing a single `datetime.date` or `datetime.datetime` object directly to the `holidays` parameter, which expects an iterable (like a list).
fixWrap single holiday dates in a list: `holidays=[date(2023, 1, 1)]`.
AttributeError: 'datetime.datetime' object has no attribute 'weekday'
You are passing `datetime.datetime` objects where `datetime.date` objects are expected (e.g., for `start_date`, `end_date`, or elements in `holidays`).
fixEnsure all date inputs are `datetime.date` objects. If you have a `datetime.datetime` object, convert it using `.date()`: `my_datetime_obj.date()`.
Upgrade
Version history
1.4latest on PyPI · released Aug 26, 2014
Audit
Dependencies
No dependency data recorded yet.