Python-ms
A Python equivalent to the JavaScript ms package.
This port of the original project supports some additional string-to-ms conversions, but otherwise the functionality is identical. This version also uses integers for everything to avoid rounding errors with floating-point numbers when using large values.
Using the project's unit tests as examples is recommended, as they cover everything.
| Type | Badges |
|---|---|
| PyPI | |
| Tests | |
| Activity | |
| QA | |
| Other |
Installation
The project is available via PyPI:
pip install python_ms
Examples
Convert from strings
import python_ms as ms
ms('2 days') # 172_800_000
ms('1d') # 86_400_000
ms('10h') # 36_000_000
ms('2.5 hrs') # 9_000_000
ms('2h') # 7_200_000
ms('1m') # 60_000
ms('5s') # 5_000
ms('1y') # 31_557_600_000
ms('100') # 100
ms('-3 days') # -259_200_000
ms('-1h') # -3_600_000
ms('-200') # -200
Convert from milliseconds
import python_ms as ms
ms(60_000) # "1m"
ms(2 * 60_000) # "2m"
ms(-3 * 60_000) # "-3m"
ms(ms('10 hours')) # "10h"
Time format written out
import python_ms as ms
ms(60_000, long=True) # "1 minute"
ms(2 * 60_000, long=True) # "2 minutes"
ms(-3 * 60_000, long=True) # "-3 minutes"
ms(ms('10 hours'), long=True) # "10 hours"
Features
- Has no dependencies aside from the standard library
- If a number is supplied to
python_ms, a string with a unit is returned - If a string that contains the number is supplied, it returns it as a number (e.g.: it returns
100for'100') - If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
Related Packages
- ms - The original JavaScript
mspackage
Caught a Bug?
- Fork this repository to your own GitHub account and then clone it to your local device
- Install
poetry(if it isn't already installed) - Run
poetry installin the project directory. This fetches development dependencies likepytestand sets up everything for you to start debugging
As always, you can run the tests using: poetry run pytest
Metadata
Release files for python_ms 1.1.3.post0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| python_ms-1.1.3.post0.tar.gz | 8.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_ms-1.1.3.post0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / python_ms-1.1.3.post0.tar.gz
| Download URL | python_ms-1.1.3.post0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
755353b1f67c95fd11f6ab1016f4d56c472fbbf18375339ff74ecfb94fbf917f
|
|
BLAKE2b-256 checksum How to use checksums |
4d2132e2b7942c90ca0168cdc213d77944943c1560b651c6657c12eef51cd40a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / python_ms-1.1.3.post0-py3-none-any.whl
| Download URL | python_ms-1.1.3.post0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2a9415a84a65ae6964ff95e8dd097538392652bbc5cc7d7750cc97b93ff9ce5
|
|
BLAKE2b-256 checksum How to use checksums |
4d33f855e78cb63cda5c0ca108d5d82eef45173e89d1e53d2306e05d99a27f8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for python_ms 1.1.3.post0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.