durationpy is a Python module designed for converting between Python's `datetime.timedelta` objects and Go's standard `time.Duration` string format. The current version, 0.10, was released on May 17, 2025, and the project demonstrates an active release cadence with several updates in recent years, indicating ongoing maintenance.
pip install durationpyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `durationpy.from_str` to parse a Go duration string into a `datetime.timedelta` object and `durationpy.to_str` to convert a `datetime.timedelta` back into a Go duration string. It also highlights the inherent precision limitation due to `datetime.timedelta`'s microsecond resolution.
Be aware of this inherent limitation. If nanosecond precision is critical, consider handling time durations as raw integer nanoseconds or using a different time library if available that supports higher precision.
Ensure all input duration strings strictly adhere to Go's specified `time.Duration` format. Pre-validate or sanitize user-provided duration strings before passing them to `durationpy.from_str`.
Install the library using pip: `pip install durationpy`
Provide a correctly formatted Go-style duration string (e.g., '10s', '1h30m', '5m2s'). Refer to the `durationpy` documentation for supported units and formats.
Ensure the input argument is a `datetime.timedelta` object. For example, `from datetime import timedelta; durationpy.to_str(timedelta(seconds=10))`.
No dependency data recorded yet.