No dependencies, just Python. Simple, fast, and efficient
some statistics ...
Pypi Version | Doc Status | Coverage | Downloads |
---|---|---|---|
Tired of heavy libraries for simple date calculations?
networkdays is the solution you've been looking for. A pure Python library, with no dependencies, to calculate business days between dates, quickly and efficiently. Ideal for Python developers and data scientists who value simplicity and performance.
- ๐ Lightweight and Fast: Without the weight of external dependencies. Perfect for microservices, scripts, and projects where every millisecond counts.
- ๐งโโ๏ธ Simple and Intuitive: A clear and straightforward API that resembles the spreadsheet functions you already know.
- ๐ช Flexible and Powerful: Support for custom holidays and days off, adapting to any calendar.
- ๐ Project Planning: Calculate work schedules based on effort hours and business days.
Install networkdays with pip and start simplifying your date calculations today.
pip install python-networkdays
Tip
Note that the package name on PyPI is python-networkdays, but you import it as networkdays.
Just like in your favorite spreadsheet, calculate the working days, disregarding weekends and holidays.
from datetime import date
from networkdays import Networkdays
# Define the holidays
HOLIDAYS = {date(2024, 12, 25), date(2025, 1, 1)}
# Create a Networkdays instance
workdays = Networkdays(
date(2024, 12, 20), # Start date
date(2025, 1, 10), # End date
HOLIDAYS # List of holidays
)
# Get the list of workdays
day_list = workdays.networkdays()
print(f"There are {len(day_list)} working days.")
# There are 14 working days.
# You can also list the weekends and holidays in the period
print(f"Holidays: {workdays.holidays()}")
# Holidays: [datetime.date(2024, 12, 25), datetime.date(2025, 1, 1)]
print(f"Weekends: {workdays.weekends()}")
# Weekends: [datetime.date(2024, 12, 21), datetime.date(2024, 12, 22), ... ]
Estimate the end date of a project based on working hours.
from datetime import date
from networkdays import JobSchedule
# Plan a 120-hour project, with 8 working hours per day,
# starting on July 1, 2024.
schedule = JobSchedule(
project_duration_hours=120,
workhours_per_day=8,
date_start=date(2024, 7, 1)
)
print(f"The project will take {schedule.bussines_days} business days.")
# The project will take 15 business days.
print(f"Starts on: {schedule.prj_starts}")
# Starts on: 07/01/24
print(f"Ends on: {schedule.prj_ends}")
# Ends on: 07/19/24
# Analyze the work distribution
print(f"Project years: {list(schedule.years())}")
# Project years: [2024]
print(f"Project months: {list(schedule.months())}")
# Project months: [7]
Work on Saturdays? No problem. networkdays adapts to your needs.
from datetime import date
from networkdays import Networkdays
# Consider only Sunday as a day off (1=Mon, 7=Sun)
saturday_workdays = Networkdays(
date(2024, 7, 1),
date(2024, 7, 31),
weekdaysoff={7} # Only Sundays
)
print(f"Working days in July (working on Saturdays): {len(saturday_workdays.networkdays())}")
# Working days in July (working on Saturdays): 27
For more details and examples, access our official documentation:
https://networkdays.readthedocs.io/
Contributions are always welcome! Feel free to open an issue or submit a pull request.
Everyone interacting with the project must follow our Code of Conduct.
This project is licensed under the MIT license. See the LICENSE file for more details.