Python datetimes made easy

Pendulum

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 datetime

DateTime

Drop-in replacement for the standard datetime class. It behaves exactly like it but with many improvements.

Manipulates your datetimes with ease.

Better timedelta

Duration

Drop-in replacement for the standard timedelta class.

Also supports years and months.

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'
Datetime-aware interval

Period

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


dt1 = pendulum.now()
dt2 = dt1.add(days=3)

# A period is the difference between 2 instances
period = dt2 - dt1

period.in_weekdays()
period.in_weekend_days()

# A period is iterable
for dt in period:
    print(dt)
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'
Easy timezones manipulation

Timezones

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

Automatic transition switching when shifting time.

Getting Started

pip install pendulum

Documentation