Parsing Time with Pendulum – Modern Date Handling in Python 2026

Data Manipulation Mar 18, 2026

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 + zoneinfo for 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=False is safe for ambiguous dates: 03/04/2026 is still guessed

Quick Summary

  • Strict ISO by default, strict=False for other formats
  • Readable arithmetic with add(), subtract() and month-aware math
  • Human-friendly output with diff_for_humans() and in_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 strptime calls with pendulum.parse()

Related Tutorials

Share:
Last updated: March 2026
Built-in Functions in Python 2026 str() in Python 2026: String Conversion + Modern Formatting & Best Practices memoryview with JAX in Python 2026: Zero-Copy NumPy → JAX Array Interop + Efficient ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + GPU Pinning & ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + ML Examples memoryview with NumPy & PyTorch in Python 2026: Zero-Copy Views, Efficient Slicing & ML Interop Examples memoryview with NumPy in Python 2026: Zero-Copy Views, Efficient Slicing & Real ML Examples memoryview() in Python 2026: Zero-Copy Magic for Large Binary Data + Real Examples import() in Python 2026: How It Works, Security Risks & Modern Alternatives (importlib) zip() in Python 2026: How to Use It, strict=True Behavior & Real-World Examples vars() in Python 2026: Accessing Object Namespace + Modern Introspection Patterns type() in Python 2026: Dynamic Type Inspection & Object Creation + Modern Patterns tuple() in Python 2026: Immutable Sequences + Modern Patterns & Best Practices super() in Python 2026: Method Resolution & Modern Inheritance Patterns sum() in Python 2026: Summing Iterables + Modern Numeric Patterns & Best Practices staticmethod() in Python 2026: Static Methods, Utility Functions & Modern Best Practices sorted() in Python 2026: Sorting Iterables + Modern Patterns & Best Practices slice() in Python 2026: Creating Slice Objects + Modern Patterns & Best Practices setattr() in Python 2026: Dynamic Attribute Setting + Modern Patterns & Safety set() in Python 2026: Mutable Sets Creation + Modern Patterns & Best Practices