{"id":1321,"library":"aniso8601","title":"aniso8601 Library","description":"aniso8601 is a Python library designed for robust parsing of ISO 8601 strings into native Python `datetime` and `timedelta` objects. It supports durations, dates, times, and datetimes, adhering strictly to the ISO 8601 standard. The current version is 10.0.1, and it maintains an active, though irregular, release cadence.","status":"active","version":"10.0.1","language":"en","source_language":"en","source_url":"https://github.com/aniso8601/aniso8601","tags":["datetime","iso8601","parsing","duration","time","date"],"install":[{"cmd":"pip install aniso8601","lang":"bash","label":"Install aniso8601"}],"dependencies":[],"imports":[{"symbol":"parse_datetime","correct":"from aniso8601.parse import parse_datetime"},{"symbol":"parse_date","correct":"from aniso8601.parse import parse_date"},{"symbol":"parse_time","correct":"from aniso8601.parse import parse_time"},{"symbol":"parse_duration","correct":"from aniso8601.parse import parse_duration"},{"note":"Exceptions were moved directly under the aniso8601 package in v10.0.0.","wrong":"from aniso8601.exceptions import ISO8601Error","symbol":"ISO8601Error","correct":"from aniso8601 import ISO8601Error"}],"quickstart":{"code":"import aniso8601.parse\nimport datetime\n\n# Parse an ISO 8601 duration string\nduration_str = \"P3Y6M4DT12H30M5S\"\nduration = aniso8601.parse.parse_duration(duration_str)\nprint(f\"Parsed Duration: {duration} (Type: {type(duration)})\\n\")\n\n# Parse an ISO 8601 datetime string with timezone\ndatetime_str = \"2023-01-15T10:00:00+01:00\"\ndt = aniso8601.parse.parse_datetime(datetime_str)\nprint(f\"Parsed Datetime: {dt} (Type: {type(dt)}, TZ: {dt.tzinfo})\\n\")\n\n# Parse an ISO 8601 datetime string (UTC)\nutc_datetime_str = \"2024-03-01T14:30:00Z\"\nutc_dt = aniso8601.parse.parse_datetime(utc_datetime_str)\nprint(f\"Parsed UTC Datetime: {utc_dt} (Type: {type(utc_dt)}, TZ: {utc_dt.tzinfo})\\n\")\n\n# Handle potential parsing errors\ntry:\n    invalid_str = \"invalid-date-string\"\n    aniso8601.parse.parse_datetime(invalid_str)\nexcept aniso8601.ISO8601Error as e:\n    print(f\"Error parsing '{invalid_str}': {e}\")","lang":"python","description":"This quickstart demonstrates parsing ISO 8601 duration and datetime strings using `aniso8601.parse.parse_duration` and `aniso8601.parse.parse_datetime`. It also shows how to catch `ISO8601Error` for invalid inputs."},"warnings":[{"fix":"Update code to expect `datetime.timedelta` and `datetime.datetime` objects. If custom behavior was required, consider extending native types or reimplementing logic.","message":"Starting with v9.0.0, the return types for `parse_duration` and `parse_datetime` changed. `parse_duration` now returns `datetime.timedelta` (instead of `aniso8601.Duration`) and `parse_datetime` returns `datetime.datetime` (instead of `aniso8601.DateTime`). Code relying on the specific `aniso8601` custom objects will break.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Upgrade to Python 3.7 or newer. Remove calls to `parse_repeating_interval` and implement custom logic if needed. Update exception import paths from `aniso8601.exceptions` to `aniso8601`.","message":"In v10.0.0, Python 3.6 support was dropped. Additionally, the `parse_repeating_interval` function was removed entirely, and all exception classes were moved directly under the `aniso8601` package (e.g., `aniso8601.ISO8601Error` instead of `aniso8601.exceptions.ISO8601Error`).","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Ensure input strings are strictly ISO 8601 compliant. Validate inputs before passing them to aniso8601 parsing functions, or wrap calls in `try...except aniso8601.ISO8601Error` blocks.","message":"aniso8601 is strict about ISO 8601 compliance. It does not attempt to 'guess' or be lenient with non-standard formats. Input strings must strictly conform to the ISO 8601 specification to be parsed successfully. This can lead to unexpected `ISO8601Error` for subtly malformed strings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always provide timezone information (e.g., '2023-01-15T10:00:00Z' for UTC or '+01:00' for an offset) if you require timezone-aware datetime objects. If you receive a naive datetime, you must explicitly localize it using a library like `pytz` or `zoneinfo` (Python 3.9+).","message":"When parsing datetimes without an explicit timezone offset (e.g., '2023-01-15T10:00:00'), `parse_datetime` will return a naive `datetime` object (i.e., `dt.tzinfo` will be `None`). It does not assume UTC or any local timezone by default for such strings.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}