icholy/durationpy

Module for converting between datetime.timedelta and Go's time.Duration strings.

Python

41

66 commits

updated Aug 26, 2026

See the code

README

durationpy

Module for converting between datetime.timedelta and Go's Duration strings.

Install

$ pip install durationpy

Parse

  • ns - nanoseconds
  • us - microseconds
  • ms - millisecond
  • s - second
  • m - minute
  • h - hour
  • d - day
  • w - week
  • mm - month
  • y - year
# parse
td = durationpy.from_str("4h3m2s1ms")

# format
durationpy.to_str(td)

Note: nanosecond precision is lost because datetime.timedelta uses microsecond resolution.

icholy/durationpy

Module for converting between datetime.timedelta and Go's time.Duration strings.

Python

41

66 commits

updated Aug 26, 2026

See the code

README

durationpy

Module for converting between datetime.timedelta and Go's Duration strings.

Install

$ pip install durationpy

Parse

  • ns - nanoseconds
  • us - microseconds
  • ms - millisecond
  • s - second
  • m - minute
  • h - hour
  • d - day
  • w - week
  • mm - month
  • y - year
# parse
td = durationpy.from_str("4h3m2s1ms")

# format
durationpy.to_str(td)

Note: nanosecond precision is lost because datetime.timedelta uses microsecond resolution.

Project health

Overall

3.3/10

Maintained

2/10

Code review

3/10
OpenSSF Scorecard

Latest release

0.11.0 · Aug 26, 2026

Releases this year

1

Significant stargazers

Wong Hoi Sing Edison

107 followers · starred Nov 2024