humanreadable


Namehumanreadable JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/thombashi/humanreadable
Summaryhumanreadable is a Python library to convert human-readable values to other units.
upload_time2023-07-22 15:36:37
maintainer
docs_urlNone
authorTsuyoshi Hombashi
requires_python>=3.7
licenseMIT License
keywords human-readable converter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. contents:: **humanreadable**
   :backlinks: top
   :depth: 2


Summary
============================================
humanreadable is a Python library to convert human-readable values to other units.

.. image:: https://badge.fury.io/py/humanreadable.svg
    :target: https://badge.fury.io/py/humanreadable
    :alt: PyPI package version

.. image:: https://img.shields.io/pypi/pyversions/humanreadable.svg
   :target: https://pypi.org/project/humanreadable
    :alt: Supported Python versions

.. image:: https://img.shields.io/pypi/implementation/humanreadable.svg
    :target: https://pypi.org/project/humanreadable
    :alt: Supported Python implementations

.. image:: https://github.com/thombashi/humanreadable/actions/workflows/lint_and_test.yml/badge.svg
    :target: https://github.com/thombashi/humanreadable/actions/workflows/lint_and_test.yml
    :alt: CI status of Linux/macOS/Windows

.. image:: https://coveralls.io/repos/github/thombashi/humanreadable/badge.svg?branch=master
    :target: https://coveralls.io/github/thombashi/humanreadable?branch=master
    :alt: Test coverage


Supported Unites
-------------------------------------------
- time (days, hours, minutes, seconds, etc.)
- bits per second


Usage
============================================

Convert a human-readable value to another unit
----------------------------------------------
:Sample Code:
    .. code-block:: python

        import humanreadable as hr

        print("\n[Examples: humanreadable.Time]")
        value = "120 sec"
        print(f"'{value}' to msecs -> {hr.Time(value).milliseconds}")
        print(f"'{value}' to minutes -> {hr.Time(value).minutes}")

        value = "12 min 40 sec"
        print(f"'{value}' to seconds -> {hr.Time(value).seconds}")

        print("\n[Examples: humanreadable.BitsPerSecond]")
        value = "1 Gbps"
        print(f"'{value}' to Mbps -> {hr.BitsPerSecond(value).mega_bps}")
        print(f"'{value}' to Kbps -> {hr.BitsPerSecond(value).kilo_bps}")
        print(f"'{value}' to Kibps -> {hr.BitsPerSecond(value).kibi_bps}")

:Output:
    .. code-block::

        [Examples: humanreadable.Time]
        '120 sec' to msecs -> 120000.0
        '120 sec' to minutes -> 2.0
        '12 minutes 40 seconds' to seconds -> 760.0

        [Examples: humanreadable.BitsPerSecond]
        '1 Gbps' to Mbps -> 1000.0
        '1 Gbps' to Kbps -> 1000000.0
        '1 Gbps' to Kibps -> 976562.5


Convert a value to a human readable string
----------------------------------------------
:Sample Code:
    .. code-block:: python

        import humanreadable as hr

        t = hr.Time("400", default_unit=hr.Time.Unit.SECOND)
        print(t.to_humanreadable())
        print(t.to_humanreadable(style="short"))

:Output:
    .. code-block::

        6 minutes 40 seconds
        6m 40s

Set default unit
-------------------------------------------
Unit for an instance is determined by input value.
If a valid unit is not found, ``default_unit`` will be used for the instance (defaults to ``None``).

:Sample Code:
    .. code-block:: python

        import humanreadable as hr

        print(hr.Time("1", default_unit=hr.Time.Unit.SECOND))

:Output:
    .. code-block::

        1.0 seconds


Units
-------------------------------------------
.. table:: Available units for ``humanreadable.Time``

    +--------------+------------------------------------------------------------+
    |     Unit     |              Available unit specifiers (str)               |
    +==============+============================================================+
    | days         | ``d``/``day``/``days``                                     |
    +--------------+------------------------------------------------------------+
    | hours        | ``h``/``hour``/``hours``                                   |
    +--------------+------------------------------------------------------------+
    | minutes      | ``m``/``min``/``mins``/``minute``/``minutes``              |
    +--------------+------------------------------------------------------------+
    | seconds      | ``s``/``sec``/``secs``/``second``/``seconds``              |
    +--------------+------------------------------------------------------------+
    | milliseconds | ``ms``/``msec``/``msecs``/``millisecond``/``milliseconds`` |
    +--------------+------------------------------------------------------------+
    | microseconds | ``us``/``usec``/``usecs``/``microsecond``/``microseconds`` |
    +--------------+------------------------------------------------------------+

.. table:: Available units for ``humanreadable.BitsPerSecond``

    +-------+--------------------------------------------------------+
    | Unit  |            Available unit specifiers (str)             |
    +=======+========================================================+
    | Kbps  | ``[kK]bps``/``[kK]bits?(/|\s?per\s?)(s|sec|second)``   |
    +-------+--------------------------------------------------------+
    | Kibps | ``[kK]ibps``/``[kK]ibits?(/|\s?per\s?)(s|sec|second)`` |
    +-------+--------------------------------------------------------+
    | Mbps  | ``[mM]bps``/``[mM]bits?(/|\s?per\s?)(s|sec|second)``   |
    +-------+--------------------------------------------------------+
    | Mibps | ``[mM]ibps``/``[mM]ibits?(/|\s?per\s?)(s|sec|second)`` |
    +-------+--------------------------------------------------------+
    | Gbps  | ``[gG]bps``/``[gG]bits?(/|\s?per\s?)(s|sec|second)``   |
    +-------+--------------------------------------------------------+
    | Gibps | ``[gG]ibps``/``[gG]ibits?(/|\s?per\s?)(s|sec|second)`` |
    +-------+--------------------------------------------------------+
    | Tbps  | ``[tT]bps``/``[tT]bits?(/|\s?per\s?)(s|sec|second)``   |
    +-------+--------------------------------------------------------+
    | Tibps | ``[tT]ibps``/``[tT]ibits?(/|\s?per\s?)(s|sec|second)`` |
    +-------+--------------------------------------------------------+
    | bps   | ``bps``/``bits?(/|\s?per\s?)(s|sec|second)``           |
    +-------+--------------------------------------------------------+


Installation
============================================
Installation: pip
------------------------------
::

    pip install humanreadable

Installation: apt (for Ubuntu)
------------------------------
::

    sudo add-apt-repository ppa:thombashi/ppa
    sudo apt update
    sudo apt install python3-humanreadable


Dependencies
============================================
- Python 3.7+
- `Python package dependencies (automatically installed) <https://github.com/thombashi/humanreadable/network/dependencies>`__

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thombashi/humanreadable",
    "name": "humanreadable",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "human-readable,converter",
    "author": "Tsuyoshi Hombashi",
    "author_email": "tsuyoshi.hombashi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f5/d3/3990cc72903cc9e614f4699cb991f393b6691e57cc4d3609b36888665e63/humanreadable-0.4.0.tar.gz",
    "platform": null,
    "description": ".. contents:: **humanreadable**\n   :backlinks: top\n   :depth: 2\n\n\nSummary\n============================================\nhumanreadable is a Python library to convert human-readable values to other units.\n\n.. image:: https://badge.fury.io/py/humanreadable.svg\n    :target: https://badge.fury.io/py/humanreadable\n    :alt: PyPI package version\n\n.. image:: https://img.shields.io/pypi/pyversions/humanreadable.svg\n   :target: https://pypi.org/project/humanreadable\n    :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/implementation/humanreadable.svg\n    :target: https://pypi.org/project/humanreadable\n    :alt: Supported Python implementations\n\n.. image:: https://github.com/thombashi/humanreadable/actions/workflows/lint_and_test.yml/badge.svg\n    :target: https://github.com/thombashi/humanreadable/actions/workflows/lint_and_test.yml\n    :alt: CI status of Linux/macOS/Windows\n\n.. image:: https://coveralls.io/repos/github/thombashi/humanreadable/badge.svg?branch=master\n    :target: https://coveralls.io/github/thombashi/humanreadable?branch=master\n    :alt: Test coverage\n\n\nSupported Unites\n-------------------------------------------\n- time (days, hours, minutes, seconds, etc.)\n- bits per second\n\n\nUsage\n============================================\n\nConvert a human-readable value to another unit\n----------------------------------------------\n:Sample Code:\n    .. code-block:: python\n\n        import humanreadable as hr\n\n        print(\"\\n[Examples: humanreadable.Time]\")\n        value = \"120 sec\"\n        print(f\"'{value}' to msecs -> {hr.Time(value).milliseconds}\")\n        print(f\"'{value}' to minutes -> {hr.Time(value).minutes}\")\n\n        value = \"12 min 40 sec\"\n        print(f\"'{value}' to seconds -> {hr.Time(value).seconds}\")\n\n        print(\"\\n[Examples: humanreadable.BitsPerSecond]\")\n        value = \"1 Gbps\"\n        print(f\"'{value}' to Mbps -> {hr.BitsPerSecond(value).mega_bps}\")\n        print(f\"'{value}' to Kbps -> {hr.BitsPerSecond(value).kilo_bps}\")\n        print(f\"'{value}' to Kibps -> {hr.BitsPerSecond(value).kibi_bps}\")\n\n:Output:\n    .. code-block::\n\n        [Examples: humanreadable.Time]\n        '120 sec' to msecs -> 120000.0\n        '120 sec' to minutes -> 2.0\n        '12 minutes 40 seconds' to seconds -> 760.0\n\n        [Examples: humanreadable.BitsPerSecond]\n        '1 Gbps' to Mbps -> 1000.0\n        '1 Gbps' to Kbps -> 1000000.0\n        '1 Gbps' to Kibps -> 976562.5\n\n\nConvert a value to a human readable string\n----------------------------------------------\n:Sample Code:\n    .. code-block:: python\n\n        import humanreadable as hr\n\n        t = hr.Time(\"400\", default_unit=hr.Time.Unit.SECOND)\n        print(t.to_humanreadable())\n        print(t.to_humanreadable(style=\"short\"))\n\n:Output:\n    .. code-block::\n\n        6 minutes 40 seconds\n        6m 40s\n\nSet default unit\n-------------------------------------------\nUnit for an instance is determined by input value.\nIf a valid unit is not found, ``default_unit`` will be used for the instance (defaults to ``None``).\n\n:Sample Code:\n    .. code-block:: python\n\n        import humanreadable as hr\n\n        print(hr.Time(\"1\", default_unit=hr.Time.Unit.SECOND))\n\n:Output:\n    .. code-block::\n\n        1.0 seconds\n\n\nUnits\n-------------------------------------------\n.. table:: Available units for ``humanreadable.Time``\n\n    +--------------+------------------------------------------------------------+\n    |     Unit     |              Available unit specifiers (str)               |\n    +==============+============================================================+\n    | days         | ``d``/``day``/``days``                                     |\n    +--------------+------------------------------------------------------------+\n    | hours        | ``h``/``hour``/``hours``                                   |\n    +--------------+------------------------------------------------------------+\n    | minutes      | ``m``/``min``/``mins``/``minute``/``minutes``              |\n    +--------------+------------------------------------------------------------+\n    | seconds      | ``s``/``sec``/``secs``/``second``/``seconds``              |\n    +--------------+------------------------------------------------------------+\n    | milliseconds | ``ms``/``msec``/``msecs``/``millisecond``/``milliseconds`` |\n    +--------------+------------------------------------------------------------+\n    | microseconds | ``us``/``usec``/``usecs``/``microsecond``/``microseconds`` |\n    +--------------+------------------------------------------------------------+\n\n.. table:: Available units for ``humanreadable.BitsPerSecond``\n\n    +-------+--------------------------------------------------------+\n    | Unit  |            Available unit specifiers (str)             |\n    +=======+========================================================+\n    | Kbps  | ``[kK]bps``/``[kK]bits?(/|\\s?per\\s?)(s|sec|second)``   |\n    +-------+--------------------------------------------------------+\n    | Kibps | ``[kK]ibps``/``[kK]ibits?(/|\\s?per\\s?)(s|sec|second)`` |\n    +-------+--------------------------------------------------------+\n    | Mbps  | ``[mM]bps``/``[mM]bits?(/|\\s?per\\s?)(s|sec|second)``   |\n    +-------+--------------------------------------------------------+\n    | Mibps | ``[mM]ibps``/``[mM]ibits?(/|\\s?per\\s?)(s|sec|second)`` |\n    +-------+--------------------------------------------------------+\n    | Gbps  | ``[gG]bps``/``[gG]bits?(/|\\s?per\\s?)(s|sec|second)``   |\n    +-------+--------------------------------------------------------+\n    | Gibps | ``[gG]ibps``/``[gG]ibits?(/|\\s?per\\s?)(s|sec|second)`` |\n    +-------+--------------------------------------------------------+\n    | Tbps  | ``[tT]bps``/``[tT]bits?(/|\\s?per\\s?)(s|sec|second)``   |\n    +-------+--------------------------------------------------------+\n    | Tibps | ``[tT]ibps``/``[tT]ibits?(/|\\s?per\\s?)(s|sec|second)`` |\n    +-------+--------------------------------------------------------+\n    | bps   | ``bps``/``bits?(/|\\s?per\\s?)(s|sec|second)``           |\n    +-------+--------------------------------------------------------+\n\n\nInstallation\n============================================\nInstallation: pip\n------------------------------\n::\n\n    pip install humanreadable\n\nInstallation: apt (for Ubuntu)\n------------------------------\n::\n\n    sudo add-apt-repository ppa:thombashi/ppa\n    sudo apt update\n    sudo apt install python3-humanreadable\n\n\nDependencies\n============================================\n- Python 3.7+\n- `Python package dependencies (automatically installed) <https://github.com/thombashi/humanreadable/network/dependencies>`__\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "humanreadable is a Python library to convert human-readable values to other units.",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/thombashi/humanreadable",
        "Source": "https://github.com/thombashi/humanreadable",
        "Tracker": "https://github.com/thombashi/humanreadable/issues"
    },
    "split_keywords": [
        "human-readable",
        "converter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "154b745e5a1aa266846df4216e84773bb77c48f95d8df6795adfdb2658afa4a3",
                "md5": "a8fc7553c5850e3f8d538d6153da0c0b",
                "sha256": "5b70257a8e88856f9b64a1f0a6fb7535c9002818465e298ca27d745b25e5675d"
            },
            "downloads": -1,
            "filename": "humanreadable-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a8fc7553c5850e3f8d538d6153da0c0b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 32185,
            "upload_time": "2023-07-22T15:36:34",
            "upload_time_iso_8601": "2023-07-22T15:36:34.944213Z",
            "url": "https://files.pythonhosted.org/packages/15/4b/745e5a1aa266846df4216e84773bb77c48f95d8df6795adfdb2658afa4a3/humanreadable-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f5d33990cc72903cc9e614f4699cb991f393b6691e57cc4d3609b36888665e63",
                "md5": "4e1d63f68352f13c345b58bb84b4edd3",
                "sha256": "2879a146f0602512addfcfba227956a3f1d23b99e9f938ff91b2085a170519ba"
            },
            "downloads": -1,
            "filename": "humanreadable-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4e1d63f68352f13c345b58bb84b4edd3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 34493,
            "upload_time": "2023-07-22T15:36:37",
            "upload_time_iso_8601": "2023-07-22T15:36:37.070556Z",
            "url": "https://files.pythonhosted.org/packages/f5/d3/3990cc72903cc9e614f4699cb991f393b6691e57cc4d3609b36888665e63/humanreadable-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-22 15:36:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thombashi",
    "github_project": "humanreadable",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "humanreadable"
}
        
Elapsed time: 0.20361s