or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

easter.mdindex.mdparser.mdrelativedelta.mdrrule.mdtz.mdutils.mdzoneinfo.md
tile.json

tessl/pypi-python-dateutil

Extensions to the standard Python datetime module

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-dateutil@2.9.x

To install, run

npx @tessl/cli install tessl/pypi-python-dateutil@2.9.0

index.mddocs/

python-dateutil

Powerful extensions to the standard Python datetime module, providing comprehensive functionality for date and time manipulation including relative deltas, date parsing, recurrence rules, timezone handling, and advanced date computations.

Package Information

  • Package Name: python-dateutil
  • Language: Python
  • Installation: pip install python-dateutil
  • Documentation: https://dateutil.readthedocs.io/en/stable/

Core Imports

import dateutil

Individual module imports:

from dateutil import relativedelta, parser, rrule, tz, easter, utils, zoneinfo

Basic Usage

from dateutil.relativedelta import relativedelta
from dateutil.parser import parse
from dateutil.tz import gettz
from datetime import datetime

# Relative date calculations
now = datetime.now()
next_month = now + relativedelta(months=1)
next_friday = now + relativedelta(weekday=4)  # Friday

# Flexible date parsing
date1 = parse("2023-12-25")
date2 = parse("Dec 25, 2023")
date3 = parse("25/12/2023", dayfirst=True)

# Timezone handling
utc = gettz('UTC')
eastern = gettz('America/New_York')
dt_utc = datetime.now(utc)
dt_eastern = dt_utc.astimezone(eastern)

Architecture

python-dateutil is organized into specialized modules that extend datetime functionality:

  • relativedelta: Relative date/time calculations and date component replacement
  • parser: Flexible parsing of date/time strings in various formats
  • rrule: Recurrence rule implementation following iCalendar RFC specification
  • tz: Comprehensive timezone support including system, file-based, and string-based timezones
  • easter: Easter date calculations using various calendar systems
  • utils: General date/time utility functions
  • zoneinfo: Access to bundled timezone database

Capabilities

Relative Date Calculations

Advanced date arithmetic supporting relative operations (add/subtract time periods) and absolute operations (set specific date components), with intelligent handling of complex scenarios like month-end dates and weekday calculations.

class relativedelta:
    def __init__(self, dt1=None, dt2=None, years=0, months=0, days=0, 
                 leapdays=0, weeks=0, hours=0, minutes=0, seconds=0, 
                 microseconds=0, year=None, month=None, day=None, 
                 weekday=None, yearday=None, nlyearday=None, hour=None, 
                 minute=None, second=None, microsecond=None): ...

# Weekday constants
MO, TU, WE, TH, FR, SA, SU = ...

Relative Date Calculations

Date and Time Parsing

Flexible parsing of date and time strings in almost any format, with support for ambiguous date resolution, timezone parsing, and high-performance ISO-8601 parsing.

def parse(timestr, parserinfo=None, **kwargs): ...
def isoparse(dt_str): ...

class parser:
    def __init__(self, parserinfo=None): ...
    def parse(self, timestr, default=None, ignoretz=False, tzinfos=None, **kwargs): ...

class parserinfo:
    def __init__(self, dayfirst=False, yearfirst=False): ...

Date and Time Parsing

Recurrence Rules

Complete implementation of iCalendar recurrence rules (RFC 5545) for generating recurring dates, with support for complex patterns, exclusions, and efficient iteration over large date ranges.

class rrule:
    def __init__(self, freq, dtstart=None, interval=1, wkst=None, count=None, 
                 until=None, bysetpos=None, bymonth=None, bymonthday=None, 
                 byyearday=None, byweekno=None, byweekday=None, byhour=None, 
                 byminute=None, bysecond=None, cache=False): ...

class rruleset:
    def __init__(self, cache=False): ...

def rrulestr(s, **kwargs): ...

# Frequency constants
YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY = ...

Recurrence Rules

Timezone Support

Comprehensive timezone handling supporting UTC, fixed offsets, system local timezone, tzfile format, Windows registry timezones, iCalendar timezones, and POSIX TZ strings.

class tzutc: ...
class tzoffset:
    def __init__(self, name, offset): ...
class tzlocal: ...
class tzfile:
    def __init__(self, fileobj, filename=None): ...

def gettz(name=None): ...
def enfold(dt, fold=1): ...
def datetime_ambiguous(dt, tz=None): ...
def datetime_exists(dt, tz=None): ...

UTC = tzutc()  # Singleton instance

Timezone Support

Easter Date Calculation

Computation of Easter Sunday dates using Western, Orthodox, and Julian calendar algorithms for any given year.

def easter(year, method=EASTER_WESTERN): ...

EASTER_JULIAN = 1
EASTER_ORTHODOX = 2
EASTER_WESTERN = 3

Easter Date Calculation

Date Utilities

General convenience functions for common date and time operations including current day calculation, timezone defaulting, and date comparison within tolerance.

def today(tzinfo=None): ...
def default_tzinfo(dt, tzinfo): ...
def within_delta(dt1, dt2, delta): ...

Date Utilities

Timezone Database Access

Access to dateutil's bundled timezone database with metadata support, providing an alternative to system timezone data.

class ZoneInfoFile:
    def __init__(self, zonefile_stream=None): ...
    def get(self, name, default=None): ...

def get_zonefile_instance(new_instance=False): ...

Timezone Database Access

Common Types

# From datetime module (used throughout dateutil)
class datetime: ...
class date: ...
class time: ...
class timedelta: ...
class tzinfo: ...

# dateutil-specific exceptions
class ParserError(ValueError): ...
class UnknownTimezoneWarning(RuntimeWarning): ...
class DeprecatedTzFormatWarning(Warning): ...