durations_nlp
A python durations parsing library, providing a straight-forward API to parse duration string representations such as 1d, 1 day 2 hours or 2 days 3h 26m 52s and convert them to numeric values.
What and Why
It's easier and more straight forward to read a duration expressed in natural language (at least for a human), as an expression rather than an amount. When writing configuration files for example:
interval: 3 hours
is easier to understand for a human than
interval: 10800 # seconds
Installation
durations_nlp can be installed via pip:
$ pip install durations_nlp
Usage
To parse a duration string representation, just instantiate a Duration object and let it work for you. A Duration representation is composed of as many <value><scale> pairs as you need to express it:
- A value is an integer amount.
- A scale is a duration unit in it's short or long form (both singular and plural).
- Duration pairs can be separated with sep characters and expressions such as
,orand
Example Input
1d2 days2 days and 4 hours4M, 22d and 6hours
Scales Reference
- Century:
c,century,centuries - Decade:
D,decade,decades - Year:
y,year,Year - Month:
M,month,months - Week:
w,week,weeks - Day:
d,day,days - Hour:
h,hour,hours - Minute:
m,minute,minutes - Second:
s,second,seconds - Millisecond:
ms,millisecond,milliseconds
Usage Example
from durations_nlp import Duration
one_hour = "1hour"
one_hour_duration = Duration(one_hour)
one_hour_duration.to_seconds()
# >>> 3600.0
one_hour_duration.to_minutes()
# >>> 60.0
# You can even compose durations in their short
# and long variations
two_days_three_hours = "2 days, 3h"
two_days_three_hours_duration = Duration(two_days_three_hours)
two_days_three_hours_duration.to_seconds()
# >>> 183600.0
two_days_three_hours_duration.to_hours()
# >>> 51.0
Metadata
Release files for durations-nlp 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| durations_nlp-1.0.1.tar.gz | 6.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| durations_nlp-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.4 kB
Release files / durations_nlp-1.0.1.tar.gz
| Download URL | durations_nlp-1.0.1.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25a87a372ddabf5fb45ed1da8fc711a53a0236c2954dc9c51590cee35dbf3136
|
|
BLAKE2b-256 checksum How to use checksums |
a182b07a77f35f4e96216b95eac3b474b4ecb724f89be8a57128497a7f6eaecd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.4 Linux/4.15.0-1077-aws
|
Release files / durations_nlp-1.0.1-py3-none-any.whl
| Download URL | durations_nlp-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91b411a2d92986c63c125c81b91181aed9ba70f5c9efded9401387783631f022
|
|
BLAKE2b-256 checksum How to use checksums |
670b393d5c30135849cc94993ddbb2a191e16cc38ff37e41cdf0d209ef6f991e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.4 Linux/4.15.0-1077-aws
|