Simple module to parse ISO 8601 dates
pip install iso8601
Documentation: https://pyiso8601.readthedocs.org/
PyPI: https://pypi.org/project/iso8601/
Source: https://github.com/micktwomey/pyiso8601
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:
https://arrow.readthedocs.io - arrow
https://pendulum.eustace.io - pendulum
https://labix.org/python-dateutil - python-dateutil
https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat - Yes, Python 3 has built in parsing too!
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.
References
https://www.cl.cam.ac.uk/~mgk25/iso-time.html - simple overview
https://web.archive.org/web/20090309040208/http://hydracen.com/dx/iso8601.htm - more detailed enumeration of valid formats.
Testing
poetry install
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:
poetry install
pytest
Releasing
just prepare-release
just do-release
Supported Python Versions
Tested against:
Python 3.7
Python 3.8
Python 3.9
Python 3.10
Python 3.11
Python 3.12
PyPy 3
Python 3 versions < 3.7 are untested but should work.
Changes
See CHANGELOG.md.
Metadata
Release files for iso8601 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iso8601-2.1.0.tar.gz | 6.5 kB | Without provenance | Details for iso8601-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iso8601-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for iso8601-2.1.0-py3-none-any.whl |
Total release size: 14.1 kB
Release files / iso8601-2.1.0.tar.gz
| Download URL | iso8601-2.1.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b1d3829ee8921c4301998c909f7829fa9ed3cbdac0d3b16af2d743aed1ba8df
|
|
BLAKE2b-256 checksum How to use checksums |
b9f3ef59cee614d5e0accf6fd0cbba025b93b272e626ca89fb70a3e9187c5d15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.11 Darwin/23.0.0
|
Release files / iso8601-2.1.0-py3-none-any.whl
| Download URL | iso8601-2.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aac4145c4dcb66ad8b648a02830f5e2ff6c24af20f4f482689be402db2429242
|
|
BLAKE2b-256 checksum How to use checksums |
6c0cf37b6a241f0759b7653ffa7213889d89ad49a2b76eb2ddf3b57b2738c347
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.11 Darwin/23.0.0
|
Security for iso8601 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.