Parsing Time with Pendulum – Modern Date Handling in Python 2026
Pendulum is a powerful, intuitive library that makes working with dates and times in Python much more pleasant than the standard library. In 2026 it remains a favorite for developers who frequently parse, manipulate, and format datetimes.
TL;DR — Why Use Pendulum?
- Fast ISO 8601 parsing, plus a lenient mode for other formats
- Beautiful, readable API
- Built-in timezone handling
- Easy duration calculations and formatting
1. Easy & Smart Parsing
import pendulum
# pendulum.parse() is strict ISO 8601 by default
for d in ["2026-03-18 14:30:00", "2026-03-18T14:30:00+05:00", "2026-W12-3"]:
print(f"{d:30} → {pendulum.parse(d)}")
# Other formats need strict=False (uses dateutil under the hood)
print(pendulum.parse("18 March 2026", strict=False))
# Relative dates are methods, not strings to parse
print(pendulum.tomorrow())
print(pendulum.today().next(pendulum.FRIDAY))
2. Working with Timezones
# Create timezone-aware datetime
dt = pendulum.now("Asia/Karachi")
print("Now in Pakistan:", dt)
# Convert to other timezones
print("In UTC:", dt.in_timezone("UTC"))
print("In New York:", dt.in_timezone("America/New_York"))
# Human readable
print("Local time:", dt.to_day_datetime_string())
3. Duration & Difference Calculations
start = pendulum.parse("2026-03-01")
end = pendulum.parse("2026-03-18 14:30")
duration = end - start
print("Days:", duration.in_days())
print("Hours:", duration.in_hours())
print("Minutes:", duration.in_minutes())
# Human friendly
print("Duration:", duration.in_words())
4. Best Practices in 2026
- Use Pendulum when you need beautiful, human-friendly date handling
- Great for logging, reporting, and user-facing date displays
- For very large datasets, combine with pandas (Pendulum works well with pandas)
- Still use standard
datetime+zoneinfofor performance-critical core logic
How pendulum.parse() Really Works
By default pendulum.parse() is a fast, strict ISO 8601 parser: dates, times, offsets, week dates and durations in ISO form are accepted, and anything else raises ParserError. With strict=False it falls back to dateutil for formats such as "18 March 2026". Strings without an offset are treated as UTC unless you pass tz=. Natural phrases such as "tomorrow" are not parsed; use helpers like pendulum.tomorrow() or .next(pendulum.FRIDAY) instead.
Worked Example: Parse, Localise and Describe
import pendulum
dt = pendulum.parse("2026-03-18 14:30", tz="Asia/Karachi")
print(dt) # 2026-03-18 14:30:00+05:00
print(dt.in_timezone("UTC")) # 2026-03-18 09:30:00+00:00
try:
pendulum.parse("next friday")
except pendulum.parsing.exceptions.ParserError:
print("not ISO - use helper methods instead")
ref = pendulum.datetime(2026, 3, 1, tz="UTC")
later = ref.add(months=1, days=2)
print(later.to_date_string()) # 2026-04-03
print(later.diff_for_humans(ref)) # 1 month after
print((later - ref).in_days()) # 33
diff_for_humans() compares two moments; in_words() on a duration spells out the length. Both are useful for reports and logs.
When Pendulum Is Worth Adding
Pendulum shines in application code that formats, shifts and explains dates for people: scheduling, reminders, invoices and log messages. Its datetimes are subclasses of the standard datetime, so they work with most libraries that expect one. For heavy number crunching on millions of rows, stay with pandas or NumPy types and use Pendulum only at the edges, such as parsing configuration values or rendering a final report.
Pin the Pendulum version in your project, because behaviour such as the default parser settings and the duration classes changed between major releases.
If you only need time zones, the standard zoneinfo module is already part of Python and may be enough. Add Pendulum when its readable helpers, such as diff_for_humans() or next(), clearly simplify your code.
Keep the parsing and the shifting separate in your code: parse once into an aware datetime, then apply every calculation to that object. This keeps errors easy to trace.
Common Mistakes
- Expecting natural-language parsing: pendulum does not parse "tomorrow"
- Forgetting the default UTC: pass
tz=for local strings - Mixing pendulum and pandas carelessly: values stored in a DataFrame become pandas Timestamps
- Assuming
strict=Falseis safe for ambiguous dates:03/04/2026is still guessed
Quick Summary
- Strict ISO by default,
strict=Falsefor other formats - Readable arithmetic with
add(),subtract()and month-aware math - Human-friendly output with
diff_for_humans()andin_words()
Conclusion
Pendulum makes date and time parsing and manipulation feel natural and enjoyable. In 2026 it continues to be an excellent choice when you want clean, readable code for handling dates, especially when dealing with user input, logs, or reporting. While the standard library has improved, Pendulum remains the most delightful way to work with time in Python.
Next steps:
- Try replacing a few messy
strptimecalls withpendulum.parse()