Pendulum is a Python package designed to simplify datetime manipulation, offering a more intuitive API and robust timezone handling than Python's native `datetime` module. It provides drop-in replacements for standard datetime classes, making integration seamless. Currently at version 3.2.0, Pendulum maintains an active release cadence, often aligning with new Python versions or significant feature enhancements.
pip install pendulumVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create timezone-aware `DateTime` objects, perform common operations like adding time, calculating human-readable differences, and converting between timezones.
Upgrade your Python environment to 3.9 or higher if you intend to use Pendulum 3.x.
Update all instances of `Period` to `Interval` and `pendulum.period()` to `pendulum.interval()` in your code.
If your code relies on the exact string format, explicitly use `dt.isoformat()` for ISO 8601, or `dt.format('...')` with custom tokens to achieve the desired output.Migrate to the new testing helpers and ensure the `[test]` extra is installed if you use time-traveling features.
Always pass the timezone using the `tz=` keyword argument: `pendulum.datetime(2026, 3, 28, tz='UTC')`.
This change primarily affects internals and improves compatibility. Ensure your Python environment meets the `>=3.9` requirement for optimal timezone handling.
No direct action required unless you were explicitly relying on `pytz` through Pendulum, in which case you should switch to `zoneinfo` or Pendulum's native timezone utilities.
Ensure Pendulum is installed in your active Python environment using pip: `pip install pendulum`.
Convert the `pendulum.DateTime` object to a standard `datetime.datetime` object before passing it to the external library: `my_pendulum_dt.in_timezone('UTC').replace(tzinfo=None) # for naive datetime` or `my_pendulum_dt.in_timezone('UTC')._datetime # for timezone-aware datetime.datetime` (though direct attribute access is generally discouraged, `to_datetime_string()` or `isoformat()` can also be used depending on the need to represent it as a string).For non-standard or complicated strings, use `pendulum.from_format()` with an explicit format string, or pass `exact=False` (formerly `strict=False`) to `pendulum.parse()` to allow it to fall back on `dateutil` parsing: `pendulum.parse('2023-01-01 10:30:00', exact=False)` or `pendulum.from_format('2023/01/01', 'YYYY/MM/DD')`.Remove the `dst_rule` argument from your `pendulum.datetime()` calls. Pendulum 3.x handles DST transitions implicitly and correctly without this explicit parameter. If specific DST behavior is needed, leverage `in_timezone()` or ensure your timezone strings are correctly specified.
Use the `add()` method with keyword arguments for time units or direct addition with `datetime.timedelta` objects: `dt.add(hours=1, minutes=30)` or `dt + timedelta(hours=1, minutes=30)`.