Skip to main content

Datetimes for Humans.

Project description

https://img.shields.io/pypi/v/maya.svg https://travis-ci.org/kennethreitz/maya.svg?branch=master https://img.shields.io/badge/SayThanks-!-1EAEDB.svg

Datetimes are very frustrating to work with in Python, especially when dealing with different locales on different systems. This library exists to make the simple things much easier, while admitting that time is an illusion (timezones doubly so).

Datetimes should be interacted with via an API written for humans.

Maya is mostly built around the headaches and use-cases around parsing datetime data from websites.

☤ Basic Usage of Maya

Behold, datetimes for humans!

>>> now = maya.now()
<MayaDT epoch=1481850660.9>

>>> tomorrow = maya.when('tomorrow')
<MayaDT epoch=1481919067.23>

>>> tomorrow.slang_date()
'tomorrow'

>>> tomorrow.slang_time()
'23 hours from now'

# Also: MayaDT.from_iso8601(...)
>>> tomorrow.iso8601()
'2017-02-10T22:17:01.445418Z'

# Also: MayaDT.from_rfc2822(...)
>>> tomorrow.rfc2822()
'Fri, 10 Feb 2017 22:17:01 GMT'

# Also: MayaDT.from_rfc3339(...)
>>> tomorrow.rfc3339()
'2017-02-10T22:17:01.44Z'

>>> tomorrow.datetime()
datetime.datetime(2016, 12, 16, 15, 11, 30, 263350, tzinfo=<UTC>)

# Automatically parse datetime strings and generate naive datetimes.
>>> scraped = '2016-12-16 18:23:45.423992+00:00'
>>> maya.parse(scraped).datetime(to_timezone='US/Eastern', naive=True)
datetime.datetime(2016, 12, 16, 13, 23, 45, 423992)

>>> rand_day = maya.when('2011-02-07', timezone='US/Eastern')
<MayaDT epoch=1297036800.0>

>>> rand_day.day
7

>>> rand_day.add(days=10).day
17

# Always.
>>> rand_day.timezone
UTC

☤ Why is this useful?

  • All timezone algebra will behave identically on all machines, regardless of system locale.

  • Complete symmetric import and export of both ISO 8601 and RFC 2822 datetime stamps.

  • Fantastic parsing of both dates written for/by humans and machines (maya.when() vs maya.parse()).

  • Support for human slang, both import and export (e.g. an hour ago).

  • Datetimes can very easily be generated, with or without tzinfo attached.

  • This library is based around epoch time, but dates before Jan 1 1970 are indeed supported, via negative integers.

  • Maya never panics, and always carries a towel.

☤ What about Delorean, Arrow, & Pendulum?

Arrow, for example, is a fantastic library, but isn’t what I wanted in a datetime library. In many ways, it’s better than Maya for certain things. In some ways, in my opinion, it’s not.

I simply desire a sane API for datetimes that made sense to me for all the things I’d ever want to do—especially when dealing with timezone algebra. Arrow doesn’t do all of the things I need (but it does a lot more!). Maya does do exactly what I need.

I think these projects complement each-other, personally. Maya is great for parsing websites. For example- Arrow supports floors and ceilings and spans of dates, which Maya does not at all.

☤ Installing Maya

Installation is easy, with pip:

$ pip install maya

✨🍰✨

☤ Like it?

Say Thanks!

How to Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.

  2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).

  3. Write a test which shows that the bug was fixed or that the feature works as expected.

  4. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maya-0.1.8.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maya-0.1.8-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file maya-0.1.8.tar.gz.

File metadata

  • Download URL: maya-0.1.8.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for maya-0.1.8.tar.gz
Algorithm Hash digest
SHA256 25ab6555a9217b8d48e81eff62745890536906c0ea6bd190adce2a3faba48130
MD5 6eec7a5fa21abe9a25d0eff11080f7ec
BLAKE2b-256 4bd88bae41c3be0c8d895a291fc219ea769b0bd712894d8998e43847bc188c18

See more details on using hashes here.

File details

Details for the file maya-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: maya-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for maya-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ea7f9519852d82410b0aa6769b7c35ce1725d150d4349ea947e495b455f183e7
MD5 085d9273a4d0d23de74cda911e0cb31d
BLAKE2b-256 0b85b85c58d5e0161bbf775abc0af76193f3a7ba2ea48ad7ea85d20a0aa19ed2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page