Skip to main content

Simple module to parse ISO 8601 dates

This module parses the most common forms of ISO 8601 date strings (e.g. 2007-01-14T20:34:22+00:00) into datetime objects.

>>> import iso8601
>>> iso8601.parse_date("2007-01-25T12:00:00Z")
datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.Utc>)
>>>

See the LICENSE file for the license this package is released under.

If you want more full featured parsing look at:

Parsed Formats

You can parse full date + times, or just the date. In both cases a datetime instance is returned but with missing times defaulting to 0, and missing days / months defaulting to 1.

Dates

  • YYYY-MM-DD

  • YYYYMMDD

  • YYYY-MM (defaults to 1 for the day)

  • YYYY (defaults to 1 for month and day)

Times

  • hh:mm:ss.nn

  • hhmmss.nn

  • hh:mm (defaults to 0 for seconds)

  • hhmm (defaults to 0 for seconds)

  • hh (defaults to 0 for minutes and seconds)

Time Zones

  • Nothing, will use the default timezone given (which in turn defaults to UTC).

  • Z (UTC)

  • +/-hh:mm

  • +/-hhmm

  • +/-hh

Where it Differs From ISO 8601

Known differences from the ISO 8601 spec:

  • You can use a “ “ (space) instead of T for separating date from time.

  • Days and months without a leading 0 (2 vs 02) will be parsed.

  • If time zone information is omitted the default time zone given is used (which in turn defaults to UTC). Use a default of None to yield naive datetime instances.

Homepage

References

Testing

  1. poetry install

  2. poetry run nox

Note that you need all the pythons installed to perform a tox run (see below). pyenv helps hugely, use pyenv install for the versions you need then use ‘pyenv local version …’ to link them in (the tox-pyenv plugin will pick them up).

Alternatively, to test only with your current python:

  1. poetry install

  2. pytest

Releasing

  1. Ensure there is a new version committed to main (use poetry version <action> to bump).

  2. Ensure README.rst changelog is up to date.

  3. Note new and previous version.

  4. rm -rf dist

  5. poetry build

  6. git log –oneline $LAST_VERSION..@ > git_log.txt

  7. gh release create –notes-file git_log.txt –title $(poetry version -s) $(poetry version -s) dist/*

  8. poetry publish

Supported Python Versions

Tested against:

  • Python 3.6

  • Python 3.7

  • Python 3.8

  • Python 3.9

  • Python 3.10

  • Python 3.11

  • PyPy 3

Python 3 versions < 3.6 are untested but should work.

Changes

unreleased

1.1.0

1.0.2

1.0.1

  • Add missing py.typed file (as per PEP 561), keeps mypy happy :D

1.0.0

  • Drop python < 3.6 support

  • Add type annotations to code

  • Remove external type annotations in pyi

  • Switch to poetry for packaging

  • Simplify internals and remove old compatability code

  • Switch to nox for testing

  • Lots of small project development changes

0.1.16

0.1.15

  • Include .pyi files in built wheels and source tarballs

0.1.14

  • Add GitHub build actions for project

  • Add project URLs in setup.py (thanks to Steve Piercy)

  • Update README links (thanks to Steve Piercy)

  • Fix handling of README in setup.py (encoding fun in 3.5, 3.6 and pypy3)

  • Fix README links (thanks to Chris Barker)

  • Add Python 3.9 to test matrix (thanks to Luciano Mammino)

  • Add type hints (thanks to Brett Cannon)

  • Derive ParseError from ValueError (thanks to Lex Robinson)

0.1.13

  • Move to GitHub (https://github.com/micktwomey/pyiso8601). Thanks go to Martin Häcker for pointing out the bitbucket project had been deleted by Atlassian!

  • Remove python 2.6, 3.2, 3.3 and 3.4 from tests

  • Add python 3.7 and 3.8 to tests

0.1.12

0.1.11

0.1.10

0.1.9

0.1.8

0.1.7

0.1.6

0.1.5

0.1.4

  • The default_timezone argument wasn’t being passed through correctly, UTC was being used in every case. Fixes issue 10.

0.1.3

  • Fixed the microsecond handling, the generated microsecond values were way too small. Fixes issue 9.

0.1.2

  • Adding ParseError to __all__ in iso8601 module, allows people to import it. Addresses issue 7.

  • Be a little more flexible when dealing with dates without leading zeroes. This violates the spec a little, but handles more dates as seen in the field. Addresses issue 6.

  • Allow date/time separators other than T.

0.1.1

  • When parsing dates without a timezone the specified default is used. If no default is specified then UTC is used. Addresses issue 4.

Download files

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

Source Distribution

iso8601-1.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

iso8601-1.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file iso8601-1.1.0.tar.gz.

File metadata

  • Download URL: iso8601-1.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Darwin/21.6.0

File hashes

Hashes for iso8601-1.1.0.tar.gz
Algorithm Hash digest
SHA256 32811e7b81deee2063ea6d2e94f8819a86d1f3811e49d23623a41fa832bef03f
MD5 29dd454d638bd684bd3466583f6724dc
BLAKE2b-256 318c1c342fdd2f4af0857684d16af766201393ef53318c15fa785fcb6c3b7c32

See more details on using hashes here.

File details

Details for the file iso8601-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: iso8601-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Darwin/21.6.0

File hashes

Hashes for iso8601-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8400e90141bf792bce2634df533dc57e3bee19ea120a87bebcd3da89a58ad73f
MD5 5e7dfa99362df5f4d50acef7a44aca72
BLAKE2b-256 656c9d72435c72adfa6e4ed1824b6df7fffbeaaf15c653881e9b041a318ba572

See more details on using hashes here.

Release history Release notifications | RSS feed

2.1.0

2 files

2.0.0

2 files

This release

1.1.0 This release

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

3 files

0.1.12

3 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

3 files

0.1.3

3 files

0.1.2

3 files

0.1.1

2 files

0.1

3 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page