Registry / serialization / pendulum

pendulum

JSON →
library3.2.0pypypi✓ verified 24d ago

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 pendulum
INSTALL
IMPORT
SIG · PENDULUM
P
pendulum
serializationpythonv3.2.0
Install
2.4s avg
Import
108ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.0 · 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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.108s · 24.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.4s · import 0.107s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

datetime
import pendulum dt = pendulum.datetime(2026, 3, 28, 10, 0, 0, tz='UTC')
from datetime import datetime dt = datetime(2026, 3, 28, 10, 0, 0)
Pendulum's `datetime` (accessed via `pendulum.datetime`) is the primary class and a drop-in replacement for the native `datetime.datetime`, offering enhanced features like automatic timezone awareness.
now
import pendulum current_time = pendulum.now('Europe/Paris')
Use `pendulum.now()` to get the current datetime, optionally specifying a timezone.
parse
import pendulum dt = pendulum.parse('2026-03-28T10:00:00+02:00')
Automatically parses various date and time string formats.

This quickstart demonstrates how to create timezone-aware `DateTime` objects, perform common operations like adding time, calculating human-readable differences, and converting between timezones.

import pendulum # Get current time in a specific timezone now_paris = pendulum.now('Europe/Paris') print(f"Current time in Paris: {now_paris}") # Create a specific datetime birthday = pendulum.datetime(1990, 7, 15, tz='America/New_York') print(f"My birthday: {birthday}") # Add time next_week = now_paris.add(weeks=1, days=2) print(f"Next week and two days: {next_week}") # Calculate difference in a human-readable format diff = next_week.diff_for_humans(now_paris) print(f"Difference: {diff}") # Convert to another timezone now_london = now_paris.in_timezone('Europe/London') print(f"Current time in London: {now_london}")
Debug
Known issues
breakingPendulum 3.0.0 dropped support for Python 2.7, 3.5, 3.6, and 3.7. Version 3.1.0 further dropped support for Python 3.8. The library now requires Python >= 3.9.
fix
Upgrade your Python environment to 3.9 or higher if you intend to use Pendulum 3.x.
affects: 3.0.0, 3.1.0
breakingThe `Period` class and its associated `period` helper were renamed to `Interval` and `interval` respectively in Pendulum 3.0.0.
fix
Update all instances of `Period` to `Interval` and `pendulum.period()` to `pendulum.interval()` in your code.
affects: >=3.0.0
breakingThe default string representation (`str(dt)`) of `DateTime` instances changed in 3.0.0 to align with Python's standard library `datetime` output (e.g., from `T` separator to space).
fix
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.
affects: >=3.0.0
breakingExisting testing helpers like `pendulum.test()` and `pendulum.set_test_now()` were removed in 3.0.0. New testing helpers, which rely on the `time-machine` library, were introduced and require installing Pendulum with the `[test]` extra (e.g., `pip install "pendulum[test]"`).
fix
Migrate to the new testing helpers and ensure the `[test]` extra is installed if you use time-traveling features.
affects: >=3.0.0
gotchaThe `tz` argument for `pendulum.datetime()` is keyword-only since Pendulum 2.x, differing from Python's native `datetime` constructor.
fix
Always pass the timezone using the `tz=` keyword argument: `pendulum.datetime(2026, 3, 28, tz='UTC')`.
affects: >=2.0.0
deprecatedThe `Timezone` class in Pendulum 3.0.0 now relies on Python's native `zoneinfo.ZoneInfo` class (available from Python 3.9+). While not a direct breaking change, users on older Python versions (not applicable for Pendulum 3.x's requirements) previously relied on Pendulum's internal timezone handling which has been streamlined.
fix
This change primarily affects internals and improves compatibility. Ensure your Python environment meets the `>=3.9` requirement for optimal timezone handling.
affects: >=3.0.0
deprecatedThe `pytz` dependency was removed in Pendulum 3.2.0, streamlining timezone management to rely on standard library features (`zoneinfo`).
fix
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.
affects: >=3.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pendulum'
The 'pendulum' library is not installed in the Python environment where the code is being executed, or the environment is not correctly activated.
fix
Ensure Pendulum is installed in your active Python environment using pip: `pip install pendulum`.
AttributeError: 'DateTime' object has no attribute 'nanosecond'
This error often occurs when a `pendulum.DateTime` object is passed to a library (like Pandas) that expects a native Python `datetime` object or has specific attribute expectations not present in `pendulum.DateTime` directly.
fix
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).
pendulum.parsing.exceptions.ParserError: Unable to parse string [...]
The `pendulum.parse()` method was unable to interpret the provided string into a valid date and time, often because the string format is not natively supported or is ambiguous.
fix
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')`.
TypeError: datetime() got an unexpected keyword argument 'dst_rule'
The `dst_rule` keyword argument was removed in Pendulum 3.0.0, which introduced breaking changes to simplify the API and improve standard library compatibility.
fix
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.
AttributeError: 'DateTime' object has no attribute 'add_timedelta'
The `add_timedelta` method was deprecated and removed in Pendulum 2.x and later, replaced by the more intuitive `add()` and `subtract()` methods, or direct arithmetic.
fix
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)`.
Upgrade
Version history
3.2.0latest on PyPI · released Jan 30, 2026
Audit
Dependencies
time-machineoptionalRequired for optional testing helpers (pendulum[test] extra).
Agent activity
13 hits · last 30 days
node
12
Resources
pendulum — pip install pendulum · libregistry