Epidemiological Weeks Calculation

2.4.0 · active · verified Thu Apr 16

EpiWeeks is a Python package designed for accurate epidemiological week calculations, adhering to both the US CDC (MMWR) and ISO week numbering systems. It provides reliable week calculations, validated against official reference data, making it essential for disease surveillance, public health reporting, and epidemiological research. The library boasts zero runtime dependencies, supports Python versions 3.10 and newer, and is actively maintained with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to create `Week` and `Year` objects, convert dates to epiweeks, and iterate through a year's weeks using both CDC and ISO systems.

from datetime import date
from epiweeks import Week, Year

# Create a Week object from year and week number
week_obj = Week(2023, 1)
print(f"Week 2023-01 starts on: {week_obj.startdate()}")
print(f"Week 2023-01 ends on: {week_obj.enddate()}")

# Get the epidemiological week for a specific date
some_date = date(2023, 1, 15)
current_week = Week.fromdate(some_date)
print(f"Date {some_date} is in epiweek: {current_week}")

# Iterate through all weeks in a year
print("First 3 weeks of 2024:")
for i, week in enumerate(Year(2024).iterweeks()):
    if i >= 3: break
    print(f"  {week} ending {week.enddate()}")

# Use ISO system
iso_week = Week.fromdate(date(2024, 1, 1), system='iso')
print(f"Date 2024-01-01 (ISO system): {iso_week} ending {iso_week.enddate()}")

view raw JSON →