Skip to content

cadu-leite/networkdays

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

79 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Python NetworkDays - calculate business/workday dates & Schedule

A lean and powerful Python library for business day calculations and schedule

No dependencies, just Python. Simple, fast, and efficient


some statistics ...

Pypi Version Doc Status Coverage Downloads
pypi version Documentation Status code coverage Downloads on Pypi

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.

Why choose networkdays?

  • ๐Ÿš€ 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.

Get started now!

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.

Practical Examples

Calculate business days between two dates

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), ... ]

Plan your Project

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]

Total Flexibility

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

Complete Documentation

For more details and examples, access our official documentation:

https://networkdays.readthedocs.io/

Contributions

Contributions are always welcome! Feel free to open an issue or submit a pull request.

Code of Conduct

Everyone interacting with the project must follow our Code of Conduct.

License

This project is licensed under the MIT license. See the LICENSE file for more details.

Necto Logo

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages