Python datetimes made easy

Pendulum

Better datetime

DateTime

Drop-in replacement for the standard datetime class.

Manipulate your datetimes with ease.

import pendulum

now = pendulum.now("Europe/Paris")

# Changing timezone
now.in_timezone("America/Toronto")

# Default support for common datetime formats
now.to_iso8601_string()

# Shifting
now.add(days=2)
Better timedelta

Duration

Drop-in replacement for the standard timedelta class.

dur = pendulum.duration(days=15)

# More properties
dur.weeks
dur.hours

# Handy methods
dur.in_hours()
360
dur.in_words(locale="en_us")
'2 weeks 1 day'

Also supports years and months.

Datetime-aware interval

Period

A Duration that is aware of the DateTime instances that created it.

dt = pendulum.now()

# A period is the difference between 2 instances
period = dt - dt.subtract(days=3)

period.in_days()

# A period is iterable
for dt in period:
    print(dt)
  
Easy timezones manipulation

Timezones

Handle timezones and DST transitions with ease and in a natural fashion.

Automatic transition switching when shifting time.

import pendulum

in_utc = pendulum.datetime(2013, 3, 31, 0, 59, 59)
tz = pendulum.timezone("Europe/Paris")
in_paris = tz.convert(in_utc)
'2013-03-31T01:59:59+01:00'

# Shifting time
in_paris = in_paris.add(seconds=1)
'2013-03-31T03:00:00+02:00'
in_paris.subtract(seconds=1)
'2013-03-31T01:59:59+01:00'

Getting Started

poetry add pendulum

Documentation