Everyday Utilities

python-dateutil

The library that quietly makes sense of next Tuesday and three months from now in code.

Install it: pip install python-dateutil

What does it do?

Python’s built-in date tools are strict and unhelpful; they don’t know that adding one month to January 31st should sensibly become February 28th rather than error out. python-dateutil fixes exactly this kind of everyday date arithmetic, along with parsing messy human-written date strings like March 3rd 2024 or 03/04/24 into something a computer can reliably work with. It also handles recurring rules, like every second Tuesday of the month, and timezone math that would otherwise take pages of fiddly code. It’s less a flashy tool and more indispensable plumbing.

See it in action

This correctly adds one month to January 31st (landing on a sensible date instead of erroring) and turns a written-out date phrase into a proper computer-readable date.

from datetime import date
from dateutil.relativedelta import relativedelta
from dateutil.parser import parse

today = date(2024, 1, 31)
print(today + relativedelta(months=1))
print(parse("March 3rd, 2024"))

Why would a non-developer care?

Nearly every calendar, reminder, or scheduling feature you’ve used has to solve these exact fiddly date problems somewhere behind the scenes, and getting them subtly wrong causes real bugs, like a recurring meeting that mysteriously shifts an hour after a timezone change. This library is one of the most common ways Python developers avoid badly reinventing that wheel.

Real-world examples

It’s one of the most widely installed packages in the entire Python ecosystem, quietly bundled as a dependency inside pandas, matplotlib, and countless other major libraries you’ve never directly asked for. If you’ve used almost any serious Python data or scheduling tool, this was almost certainly running underneath it.

Who uses it

Virtually every Python developer who touches dates, often without realizing it, since it arrives as a dependency of much bigger libraries.

How it compares to alternatives

Arrow and Pendulum are newer, more human-friendly wrappers that both actually build on top of python-dateutil rather than replacing it, meaning most nicer-date-library alternatives still rely on this one underneath.

Fun fact

Despite being one of the most-installed packages in the Python world, most people who benefit from python-dateutil have never installed it themselves; it rides in silently as a dependency of other tools.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries