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

This was originally hosted at https://code.google.com/p/pyiso8601/

References

Testing

  1. pip install -r dev-requirements.txt

  2. tox

Note that you need all the pythons installed to perform a tox run (see below). Homebrew helps a lot on the mac, however you wind up having to add cellars to your PATH or symlinking the pythonX.Y executables.

Alternatively, to test only with your current python:

  1. pip install -r dev-requirements.txt

  2. py.test –verbose iso8601

Supported Python Versions

Tested against:

  • Python 2.6

  • Python 2.7

  • Python 3.2

  • Python 3.3

  • Python 3.4

  • Python 3.5

  • Python 3.6

  • PyPy

  • PyPy 3

Python 3.0 and 3.1 are untested but should work (tests didn’t run under them when last tried).

Jython is untested but should work (tests failed to run).

Python 2.5 is not supported (too old for the tests for the most part). It could work with some small changes but I’m not supporting it.

Changes

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.

Metadata

Release files for iso8601 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iso8601 0.1.12
File Size Uploaded
iso8601-0.1.12.tar.gz 8.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for iso8601 0.1.12
File Interpreter ABI Platform
iso8601-0.1.12-py3-none-any.whl Python 3 none any Details
iso8601-0.1.12-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 33.0 kB

Release files / iso8601-0.1.12.tar.gz

Download URL iso8601-0.1.12.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
49c4b20e1f38aa5cf109ddcd39647ac419f928512c869dc01d5c7098eddede82
BLAKE2b-256 checksum
How to use checksums
45133db24895497345fb44c4248c08b16da34a9eb02643cea2754b21b5ed08b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / iso8601-0.1.12-py3-none-any.whl

Download URL iso8601-0.1.12-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbbae5fb4a7abfe71d4688fd64bff70b91bbd74ef6a99d964bab18f7fdf286dd
BLAKE2b-256 checksum
How to use checksums
5cdc44e9065ac128f89c6abe0ed6dc1726b6a8a6f3a59cbbdc986bd42000964d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / iso8601-0.1.12-py2.py3-none-any.whl

Download URL iso8601-0.1.12-py2.py3-none-any.whl
Size 12.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
210e0134677cc0d02f6028087fee1df1e1d76d372ee1db0bf30bf66c5c1c89a3
BLAKE2b-256 checksum
How to use checksums
ef577162609dab394d38bbc7077b7ba0a6f10fb09d8b7701ea56fa1edc0c4345
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.1.0

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.13

3 release files

This release

0.1.12 This release

3 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

3 release files

0.1.3

3 release files

0.1.2

3 release files

0.1.1

2 release files

0.1

3 release 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