Registry / serialization / backports-datetime-fromisoformat

backports-datetime-fromisoformat

JSON →
library2.0.3pypypi✓ verified 25d ago

This library provides a backport of Python 3.11's extended `datetime.fromisoformat` functionality to older Python versions (prior to 3.11). It allows parsing a wider range of ISO 8601 formatted strings, including those with timezone offsets using colons and fractional seconds. The current version is 2.0.3, with releases occurring on an as-needed basis to address compatibility or new Python version changes.

pip install "backports-datetime-fromisoformat; python_version < '3.11'"
INSTALL
IMPORT
SIG · BACKPORTS-DATETIME
B
backports-datetime-fromisoformat
serializationpythonv2.0.3
Install
1.6s avg
Import
5ms
Disk
45MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 1.5s
py 3.11
✓ —
✓ 1.55s
py 3.12
✓ —
✓ 1.4s
py 3.13
1/2 runs
1/2 runs
py 3.9
✓ —
✓ 1.8s
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

datetime.fromisoformat
import datetime import backports.datetime_fromisoformat
from backports.datetime_fromisoformat import fromisoformat
This library monkey-patches the built-in `datetime.datetime` and `datetime.date` objects. You must import `datetime` first, then `backports.datetime_fromisoformat` to apply the patch. It does not expose `fromisoformat` directly from its own namespace.

This example demonstrates how to use the backported `fromisoformat` method. By importing `backports.datetime_fromisoformat` after `datetime`, it monkey-patches the standard library's `datetime` objects to accept ISO 8601 strings that conform to Python 3.11's broader parsing capabilities, such as timezone offsets with colons.

import datetime import backports.datetime_fromisoformat # This string would fail on Python < 3.11 without the backport due to the colon in the timezone offset isodate_str = "2023-10-27T10:00:00.123456+05:30" try: dt_object = datetime.datetime.fromisoformat(isodate_str) print(f"Successfully parsed: {dt_object}") print(f"Type: {type(dt_object)}") except ValueError as e: print(f"Error parsing date: {e}")
Debug
Known issues
gotchaThis library relies on monkey-patching. The `datetime.fromisoformat` method will only be extended if `backports.datetime_fromisoformat` is imported *after* the `datetime` module.
fix
Always ensure `import datetime` appears before `import backports.datetime_fromisoformat` in your code.
affects: all
breakingVersion 2.0.0 changed the underlying logic for the backported `fromisoformat` methods. Prior to 2.0.0, it backported Python 3.7's logic; from 2.0.0 onwards, it backports Python 3.11's logic, supporting a wider range of ISO 8601 formats.
fix
Applications migrating from 1.x.x to 2.x.x should be aware that `fromisoformat` will now accept more varied ISO 8601 strings. This is generally an improvement, but verify if any strict parsing assumptions were made based on older 3.7 behavior.
affects: >=2.0.0 (compared to <2.0.0)
gotchaThis library is designed for Python versions older than 3.11. Installing and importing it on Python 3.11 or newer has no effect on `datetime.fromisoformat` and adds unnecessary overhead.
fix
Conditionally install the package using environment markers in your `pyproject.toml` or `requirements.txt`: `backports-datetime-fromisoformat; python_version < '3.11'`.
affects: all
Upgrade
Version history
2.0.3latest on PyPI · released Dec 28, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
backports-datetime-fromisoformat — pip install backports-datetime-fromisoformat · libregistry