Install & Compatibility
Where this runs
tested against v2.9.0.post0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.038s · 18.6MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.8s · import 0.036s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
parser.parse
✓ from dateutil import parser; parser.parse('2024-01-15')
✗ import dateutil; dateutil.parser.parse('2024-01-15') # works on 3.7+ via lazy import but not guaranteed in all environments
Always import the submodule explicitly for clarity. The top-level lazy-import shortcut (PEP 562, added in 2.9.0) only works on Python 3.7+.
parser.isoparse
✓ from dateutil.parser import isoparse
Use isoparse() for strict ISO 8601 strings instead of parse(); parse() is more permissive and may silently misinterpret ambiguous ISO strings.
relativedelta
✓ from dateutil.relativedelta import relativedelta
✗ from dateutil.relativedelta import *
Wildcard import pulls in weekday constants (MO, TU, ...) that can shadow calendar/rrule symbols; prefer explicit import.
rrule / DAILY / WEEKLY / MONTHLY / YEARLY
✓ from dateutil.rrule import rrule, DAILY, WEEKLY, MONTHLY, YEARLY, rruleset
Frequency constants (DAILY, WEEKLY, etc.) must be imported from dateutil.rrule; they are not available at the top-level dateutil namespace.
gettz
✓ from dateutil.tz import gettz, tzutc, tzlocal
gettz() returns None (not an exception) when the timezone name is unrecognized — always check for None before using the result.
ParserError
✓ from dateutil.parser import ParserError
✗ except ValueError
Since 2.8.1 parse() raises ParserError (a ValueError subclass) on failure. Catching only ValueError still works but catching ParserError is more precise.
Demonstrates flexible string parsing, isoparse, relativedelta month arithmetic, timezone handling with gettz, and explicit dayfirst flag for ambiguous dates.
from datetime import datetime
from dateutil import parser
from dateutil.relativedelta import relativedelta
from dateutil.tz import gettz, tzutc
# 1. Flexible string parsing
dt = parser.parse("March 15, 2024 3:30 PM")
print("Parsed:", dt)
# 2. ISO 8601 with timezone
dt_aware = parser.isoparse("2024-03-15T15:30:00+05:30")
print("ISO aware:", dt_aware)
# 3. Relative delta arithmetic (month-aware)
now = datetime(2024, 1, 31, tzinfo=tzutc())
one_month_later = now + relativedelta(months=1)
print("One month later:", one_month_later) # 2024-02-29 (leap year)
# 4. Timezone-aware datetime
nyc = gettz("America/New_York")
if nyc is None:
raise RuntimeError("Could not resolve timezone; install tzdata package")
dt_nyc = datetime(2024, 3, 15, 12, 0, tzinfo=nyc)
print("NYC time:", dt_nyc)
# 5. Ambiguous date: always set dayfirst/yearfirst explicitly
ambiguous = parser.parse("04/05/2024", dayfirst=False) # May 4
print("MM/DD:", ambiguous.date())
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dateutil'
The 'python-dateutil' package, which provides the 'dateutil' module, is not installed in the Python environment.
fixpip install python-dateutil
ValueError: Unknown string format
The 'dateutil.parser.parse' function could not interpret the provided date string because its format was ambiguous or not recognized.
fixProvide date strings in clear, standard formats, use 'parser.isoparse' for ISO 8601, or pass 'dayfirst=True' / 'yearfirst=True' to 'parser.parse' for ambiguous formats.
AttributeError: module 'dateutil' has no attribute 'parse'
The 'parse' function is located within the 'dateutil.parser' submodule, but the user attempted to call it directly from the top-level 'dateutil' module.
fixImport the 'parser' submodule explicitly, e.g., 'from dateutil import parser' or 'import dateutil.parser'.
TypeError: unsupported operand type(s) for +: 'datetime.date' and 'relativedelta'
The 'relativedelta' object is being added to a 'datetime.date' object, which does not support direct arithmetic with 'relativedelta'; it only works with 'datetime.datetime' objects.
fixConvert the 'datetime.date' object to a 'datetime.datetime' object before adding the 'relativedelta', or ensure you are working with 'datetime.datetime' objects from the start.
Upgrade
Version history
2.9.0.post0latest on PyPI · released Mar 1, 2024
Audit
Dependencies
sixrequiredPython 2/3 compatibility shim; still a hard runtime dependency in 2.9.x even on Python 3
tzdataoptionalIANA timezone database on platforms without /usr/share/zoneinfo (e.g. Windows); needed for dateutil.tz.gettz() to resolve IANA names reliably