Typing stubs for python-dateutil

2.9.0.20260323 · active · verified Sat Mar 28

types-python-dateutil provides static typing stubs for the popular `python-dateutil` library. It allows type checkers like Mypy or Pyright to verify code that uses `python-dateutil`, catching potential type-related errors before runtime. This package is part of the typeshed project and aims to provide accurate annotations for `python-dateutil==2.9.*`. Updates are released frequently, often daily, directly from the typeshed repository. The current version is 2.9.0.20260323.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of `dateutil.parser.parse` and `dateutil.relativedelta` with type annotations. Installing `types-python-dateutil` provides these annotations, allowing static type checkers to ensure correct usage of `python-dateutil` functions and classes.

from datetime import datetime
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta, MO

# Enable type checking in your editor or via a tool like Mypy
# E.g., run `mypy your_script.py`

def process_date_string(date_str: str) -> datetime:
    """Parses a date string and returns a datetime object."""
    return parse(date_str)

def calculate_future_date(start_date: datetime) -> datetime:
    """Calculates a future date using relativedelta."""
    # Add 1 month and move to the 1st Monday
    return start_date + relativedelta(months=1, weekday=MO(1))

current_time_str: str = "2024-03-28 10:30:00 UTC"
parsed_dt: datetime = process_date_string(current_time_str)
print(f"Parsed datetime: {parsed_dt}")

future_dt: datetime = calculate_future_date(parsed_dt)
print(f"Future datetime: {future_dt}")

# Example where type checker would catch an error (uncomment to test):
# def expects_string(s: str):
#     print(s)
# expects_string(123) # Mypy would report: Argument 's' to 'expects_string' has incompatible type "int"; expected "str"

view raw JSON →