pytimeparse (GitHub) can parse many format of time representations, for examples, 3h23m or 5 hrs, 34 mins, 56 secs. Just little over a week ago, there was a package about duration, but this package was much better and more robust.

It returns parsed result in seconds as an integer if possible, or floating-point number:


from pytimeparse.timeparse import timeparse
>>> timeparse('1.2 minutes')
72
>> import datetime
>>> timeparse('1 day, 14:20:16')
138016
>>> str(datetime.timedelta(seconds=138016))
'1 day, 14:20:16'

Regular expressions are used to parse various formats, the inspiration was a Stack Overflow question. pytimeparse is written by Will Roberts under the MIT License, currently version 1.0.0 (2014-04-14).