Registry / data / workdays

workdays

JSON →
library1.4pypypi✓ verified 85d ago

The `workdays` library provides utility functions to calculate working days between two dates, extending Python's standard `datetime` module. The current version is 1.5, with an infrequent release cadence focused on maintenance and minor enhancements.

pip install workdays
INSTALL
IMPORT
SIG · WORKDAYS
W
workdays
datapythonv1.4
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.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}")
Debug
Known issues
breakingVersion 1.5 (released Feb 2023) introduced "flexibility of weekends". While not explicitly detailed as breaking, if your code relied on specific implicit default weekend behavior prior to 1.5, it's safest to explicitly define the `weekend_days` argument in your `networkdays` calls to maintain consistent behavior.
fix
Review existing `networkdays` calls and consider explicitly setting the `weekend_days` parameter, e.g., `weekend_days=[6, 7]` for Saturday and Sunday.
affects: >=1.5
gotchaThe `holidays` argument for `networkdays` expects an iterable (e.g., a list or tuple) containing `datetime.date` objects. Passing strings, `datetime.datetime` objects, or a single `datetime.date` object directly (without being in a list) will lead to `TypeError` or incorrect calculations.
fix
Ensure `holidays` is always an iterable of `datetime.date` objects. Convert strings using `datetime.strptime().date()` and `datetime.datetime` objects using `.date()`.
affects: All
gotchaVersions of `workdays` prior to `1.2` had known compatibility issues with Python 3. If you are running an older version on Python 3 and encounter unexpected errors, an upgrade is necessary.
fix
Upgrade to the latest version of `workdays` using `pip install --upgrade workdays`.
affects: <1.2
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.
fix
Convert 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).
fix
Wrap 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`).
fix
Ensure 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.

Agent activity
41 hits · last 30 days
node
32
OpenAI (training)
1
Resources
workdays — pip install workdays · libregistry