This module parses the most common forms of ISO 8601 date strings (e.g., 2007-01-14T20:34:22+00:00) into `datetime` objects. It simplifies the process of converting various ISO 8601 date and time formats into Python's native `datetime` types. The library is actively maintained, with a typical release cadence of a few minor/patch versions per year, ensuring compatibility and bug fixes.
pip install iso8601Verified import paths — ran on the pinned version, not inferred.
The `parse_date` function is the main entry point for parsing ISO 8601 strings. It automatically handles various common formats including full datetimes with and without timezones, and date-only strings. By default, missing timezone information will result in a UTC-aware datetime object unless a `default_timezone` is specified or set to `None` for naive datetimes.
Upgrade to Python 3.7 or newer, or pin `iso8601` to `<2.0.0`.
Upgrade to Python 3.6 or newer, or pin `iso8601` to `<1.0.0` for Python 2.x environments.
Be aware that `iso8601` is more permissive than strict ISO 8601. If strict adherence is critical, pre-validation might be necessary or consider `datetime.fromisoformat` (Python 3.7+) for stricter parsing of common formats.
Ensure your code explicitly handles 'Z' for UTC or upgrade to >=0.1.8 for correct behavior.
Use `iso8601.parse_date(datestring, default_timezone=None)` to get a naive `datetime` object for strings lacking timezone information.
pip install iso8601
Use `iso8601.parse_date()` instead of `iso8601.parse()`.
Ensure the input string strictly adheres to a valid ISO 8601 format supported by the library, or use a more flexible parsing library like `python-dateutil` for highly variable inputs.