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

Pendulum

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

Manipulates your datetimes with ease.

Better timedelta

Interval

Drop-in replacement for the standard timedelta class.

Avoid the hassle of computing things yourself.

it = pendulum.interval(days=15)

# More properties
it.weeks
it.hours

# Handy methods
it.in_hours()
360
it.in_words(locale='en_us')
'2 weeks 1 day'
Datetime-aware interval

Period

An Interval that is aware of the Pendulum 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.create(2013, 3, 31, 0, 59, 59, 999999)
tz = pendulum.timezone('Europe/Paris')
in_paris = tz.convert(in_utc)
'2013-03-31T01:59:59.999999+01:00'

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

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