python-ms


Namepython-ms JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://pypi.org/project/python-ms/
SummaryA Python equivalent to the JavaScript ms package.
upload_time2023-05-28 21:22:58
maintainerLari Liuhamo
docs_urlNone
authorLari Liuhamo
requires_python>=3.10,<4.0
licenseMIT
keywords package python3 time
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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         | ![Python versions](https://img.shields.io/pypi/pyversions/python-ms?logo=python) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/python-ms) ![Wheel](https://img.shields.io/pypi/wheel/python-ms?logo=pypi) ![Downloads](https://img.shields.io/pypi/dm/python-ms?logo=pypi) [![Version](https://img.shields.io/pypi/v/python-ms)](https://pypi.org/project/python-ms/) |
| Tests        | [![codecov](https://codecov.io/gh/Diapolo10/python-ms/branch/main/graph/badge.svg?token=zBlgCd32Aq)](https://codecov.io/gh/Diapolo10/python-ms) ![Unit tests](https://github.com/diapolo10/python-ms/workflows/Unit%20tests/badge.svg) ![Pylint](https://github.com/diapolo10/python-ms/workflows/Pylint/badge.svg) ![Flake8](https://github.com/diapolo10/python-ms/workflows/Flake8/badge.svg) ![Deploy to PyPI](https://github.com/diapolo10/python-ms/workflows/Deploy%20to%20PyPI/badge.svg) |
| Activity     | ![GitHub contributors](https://img.shields.io/github/contributors/diapolo10/python-ms) ![Last commit](https://img.shields.io/github/last-commit/diapolo10/python-ms?logo=github) ![GitHub all releases](https://img.shields.io/github/downloads/diapolo10/python-ms/total?logo=github) ![GitHub issues](https://img.shields.io/github/issues/diapolo10/python-ms) ![GitHub closed issues](https://img.shields.io/github/issues-closed/diapolo10/python-ms) ![GitHub pull requests](https://img.shields.io/github/issues-pr/diapolo10/python-ms) ![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/diapolo10/python-ms) |
| QA           | [![CodeFactor](https://www.codefactor.io/repository/github/diapolo10/python-ms/badge?logo=codefactor)](https://www.codefactor.io/repository/github/diapolo10/python-ms) [![Rating](https://img.shields.io/librariesio/sourcerank/pypi/python-ms)](https://libraries.io/github/Diapolo10/python-ms/sourcerank) |
| Other        | [![License](https://img.shields.io/github/license/diapolo10/python-ms)](https://opensource.org/licenses/MIT) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fpython-ms.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fpython-ms?ref=badge_shield) [![Known Vulnerabilities](https://snyk.io/test/github/diapolo10/python-ms/badge.svg)](https://snyk.io/test/github/diapolo10/python-ms) ![Repository size](https://img.shields.io/github/repo-size/diapolo10/python-ms?logo=github) ![Code size](https://img.shields.io/github/languages/code-size/diapolo10/python-ms?logo=github) ![Lines of code](https://img.shields.io/tokei/lines/github/diapolo10/python-ms?logo=github) |

## Installation

The project is available via PyPI:

```sh
pip install python_ms
```

## Examples

### Convert from strings

```python
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

```python
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

```python
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 `100` for `'100'`)
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned

## Related Packages

- [ms](https://github.com/vercel/ms) - The original JavaScript `ms` package

## Caught a Bug?

1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
2. Install `poetry` (if it isn't already installed)
3. Run `poetry install` in the project directory. This fetches development dependencies like `pytest` and sets up everything for you to start debugging

As always, you can run the tests using: `poetry run pytest`

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/python-ms/",
    "name": "python-ms",
    "maintainer": "Lari Liuhamo",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "lari.liuhamo+pypi@gmail.com",
    "keywords": "package,python3,time",
    "author": "Lari Liuhamo",
    "author_email": "lari.liuhamo+pypi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0e/8f/cbe92a1ff86bd5849a62c2e7943dee50a3333596d2a84be98bc973f71b08/python_ms-1.1.0.tar.gz",
    "platform": null,
    "description": "# Python-ms\n\nA Python equivalent to the JavaScript `ms` package.\n\nThis port of the original project supports some additional string-to-ms\nconversions, but otherwise the functionality is identical. This version\nalso uses integers for everything to avoid rounding errors with\nfloating-point numbers when using large values.\n\nUsing the project's unit tests as examples is recommended, as they cover\neverything.\n\n| Type         | Badges |\n|--------------|---|\n| PyPI         | ![Python versions](https://img.shields.io/pypi/pyversions/python-ms?logo=python) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/python-ms) ![Wheel](https://img.shields.io/pypi/wheel/python-ms?logo=pypi) ![Downloads](https://img.shields.io/pypi/dm/python-ms?logo=pypi) [![Version](https://img.shields.io/pypi/v/python-ms)](https://pypi.org/project/python-ms/) |\n| Tests        | [![codecov](https://codecov.io/gh/Diapolo10/python-ms/branch/main/graph/badge.svg?token=zBlgCd32Aq)](https://codecov.io/gh/Diapolo10/python-ms) ![Unit tests](https://github.com/diapolo10/python-ms/workflows/Unit%20tests/badge.svg) ![Pylint](https://github.com/diapolo10/python-ms/workflows/Pylint/badge.svg) ![Flake8](https://github.com/diapolo10/python-ms/workflows/Flake8/badge.svg) ![Deploy to PyPI](https://github.com/diapolo10/python-ms/workflows/Deploy%20to%20PyPI/badge.svg) |\n| Activity     | ![GitHub contributors](https://img.shields.io/github/contributors/diapolo10/python-ms) ![Last commit](https://img.shields.io/github/last-commit/diapolo10/python-ms?logo=github) ![GitHub all releases](https://img.shields.io/github/downloads/diapolo10/python-ms/total?logo=github) ![GitHub issues](https://img.shields.io/github/issues/diapolo10/python-ms) ![GitHub closed issues](https://img.shields.io/github/issues-closed/diapolo10/python-ms) ![GitHub pull requests](https://img.shields.io/github/issues-pr/diapolo10/python-ms) ![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/diapolo10/python-ms) |\n| QA           | [![CodeFactor](https://www.codefactor.io/repository/github/diapolo10/python-ms/badge?logo=codefactor)](https://www.codefactor.io/repository/github/diapolo10/python-ms) [![Rating](https://img.shields.io/librariesio/sourcerank/pypi/python-ms)](https://libraries.io/github/Diapolo10/python-ms/sourcerank) |\n| Other        | [![License](https://img.shields.io/github/license/diapolo10/python-ms)](https://opensource.org/licenses/MIT) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fpython-ms.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fpython-ms?ref=badge_shield) [![Known Vulnerabilities](https://snyk.io/test/github/diapolo10/python-ms/badge.svg)](https://snyk.io/test/github/diapolo10/python-ms) ![Repository size](https://img.shields.io/github/repo-size/diapolo10/python-ms?logo=github) ![Code size](https://img.shields.io/github/languages/code-size/diapolo10/python-ms?logo=github) ![Lines of code](https://img.shields.io/tokei/lines/github/diapolo10/python-ms?logo=github) |\n\n## Installation\n\nThe project is available via PyPI:\n\n```sh\npip install python_ms\n```\n\n## Examples\n\n### Convert from strings\n\n```python\nimport python_ms as ms\n\nms('2 days')  # 172_800_000\nms('1d')      # 86_400_000\nms('10h')     # 36_000_000\nms('2.5 hrs') # 9_000_000\nms('2h')      # 7_200_000\nms('1m')      # 60_000\nms('5s')      # 5_000\nms('1y')      # 31_557_600_000\nms('100')     # 100\nms('-3 days') # -259_200_000\nms('-1h')     # -3_600_000\nms('-200')    # -200\n```\n\n### Convert from milliseconds\n\n```python\nimport python_ms as ms\n\nms(60_000)          # \"1m\"\nms(2 * 60_000)      # \"2m\"\nms(-3 * 60_000)     # \"-3m\"\nms(ms('10 hours'))  # \"10h\"\n```\n\n### Time format written out\n\n```python\nimport python_ms as ms\n\nms(60_000, long=True)          # \"1 minute\"\nms(2 * 60_000, long=True)      # \"2 minutes\"\nms(-3 * 60_000, long=True)     # \"-3 minutes\"\nms(ms('10 hours'), long=True)  # \"10 hours\"\n```\n\n## Features\n\n- Has no dependencies aside from the standard library\n- If a number is supplied to `python_ms`, a string with a unit is returned\n- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)\n- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned\n\n## Related Packages\n\n- [ms](https://github.com/vercel/ms) - The original JavaScript `ms` package\n\n## Caught a Bug?\n\n1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device\n2. Install `poetry` (if it isn't already installed)\n3. Run `poetry install` in the project directory. This fetches development dependencies like `pytest` and sets up everything for you to start debugging\n\nAs always, you can run the tests using: `poetry run pytest`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python equivalent to the JavaScript ms package.",
    "version": "1.1.0",
    "project_urls": {
        "Changelog": "https://github.com/Diapolo10/python-ms/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/Diapolo10/python-ms/tree/main/docs",
        "Homepage": "https://pypi.org/project/python-ms/",
        "Repository": "https://github.com/Diapolo10/python-ms",
        "Tracker": "https://github.com/Diapolo10/python-ms/issues"
    },
    "split_keywords": [
        "package",
        "python3",
        "time"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c86c84da3a8f309361f59f1b81a14e353bf9d1ed8cd5c688c65e5aa407b6c65",
                "md5": "89b9e40cf6266ec14c819baea5d4f9d3",
                "sha256": "a78a77685c4e67b6142f5d96a1e1d4c79aaee9c862331f392198f17ed47db588"
            },
            "downloads": -1,
            "filename": "python_ms-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89b9e40cf6266ec14c819baea5d4f9d3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 8817,
            "upload_time": "2023-05-28T21:22:57",
            "upload_time_iso_8601": "2023-05-28T21:22:57.087225Z",
            "url": "https://files.pythonhosted.org/packages/3c/86/c84da3a8f309361f59f1b81a14e353bf9d1ed8cd5c688c65e5aa407b6c65/python_ms-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0e8fcbe92a1ff86bd5849a62c2e7943dee50a3333596d2a84be98bc973f71b08",
                "md5": "890c4a9327a59eaccd4e4912c1054923",
                "sha256": "c8fe7e2424f2913a23c66a2f26a3eb1f5ff429765aa68aa6620b037a52191967"
            },
            "downloads": -1,
            "filename": "python_ms-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "890c4a9327a59eaccd4e4912c1054923",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 8193,
            "upload_time": "2023-05-28T21:22:58",
            "upload_time_iso_8601": "2023-05-28T21:22:58.253150Z",
            "url": "https://files.pythonhosted.org/packages/0e/8f/cbe92a1ff86bd5849a62c2e7943dee50a3333596d2a84be98bc973f71b08/python_ms-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-28 21:22:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Diapolo10",
    "github_project": "python-ms",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-ms"
}
        
Elapsed time: 0.08137s