{"id":15685927,"url":"https://github.com/ofek/binary","last_synced_at":"2025-04-09T20:04:43.190Z","repository":{"id":28404285,"uuid":"118304995","full_name":"ofek/binary","owner":"ofek","description":"Easily convert between binary and SI units (kibibyte, kilobyte, etc.).","archived":false,"fork":false,"pushed_at":"2024-12-05T16:09:48.000Z","size":37,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T20:04:37.888Z","etag":null,"topics":["binary-prefix","conversion","library","python","si-units","units-of-measurement"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ofek.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-21T04:44:27.000Z","updated_at":"2025-03-12T05:30:13.000Z","dependencies_parsed_at":"2025-01-02T05:11:33.078Z","dependency_job_id":"8f841996-9301-4ff5-b910-dff5708aa55c","html_url":"https://github.com/ofek/binary","commit_stats":{"total_commits":30,"total_committers":2,"mean_commits":15.0,"dds":"0.30000000000000004","last_synced_commit":"d67bd4dedde9f9ef2198db89859154e449e2fcfb"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek%2Fbinary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek%2Fbinary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek%2Fbinary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek%2Fbinary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ofek","download_url":"https://codeload.github.com/ofek/binary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103868,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-prefix","conversion","library","python","si-units","units-of-measurement"],"created_at":"2024-10-03T17:33:08.929Z","updated_at":"2025-04-09T20:04:43.166Z","avatar_url":"https://github.com/ofek.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"binary\n======\n\n.. image:: https://img.shields.io/pypi/v/binary.svg?style=flat-square\n    :target: https://pypi.org/project/binary\n    :alt: Latest PyPI version\n\n.. image:: https://github.com/ofek/binary/workflows/test/badge.svg\n    :target: https://github.com/ofek/binary/actions/workflows/test.yml\n    :alt: GitHub Actions\n\n.. image:: https://img.shields.io/codecov/c/github/ofek/binary/master.svg?style=flat-square\n    :target: https://codecov.io/gh/ofek/binary\n    :alt: Codecov\n\n.. image:: https://img.shields.io/pypi/pyversions/binary.svg?style=flat-square\n    :target: https://pypi.org/project/binary\n    :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/l/binary.svg?style=flat-square\n    :target: https://choosealicense.com/licenses\n    :alt: License\n\n-----\n\n``binary`` provides a bug-free and easy way to convert between and within\nbinary (`IEC`_) and decimal (`SI`_) units.\n\n.. contents:: **Table of Contents**\n    :backlinks: none\n\nInstallation\n------------\n\n``binary`` is distributed on `PyPI \u003chttps://pypi.org\u003e`_ as a universal\nwheel and is available on Linux/macOS and Windows and supports\nPython 2.7/3.5+ and PyPy.\n\n.. code-block:: bash\n\n    $ pip install binary\n\nExamples\n--------\n\nLet's import what we need:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from binary import BinaryUnits, DecimalUnits, convert_units\n\n**Basic conversion:**\n\n.. code-block:: python\n\n    \u003e\u003e\u003e convert_units(1536, BinaryUnits.KB, BinaryUnits.MB)\n    (1.5, 'MiB')\n\n**How much actual storage your new hard drive has:**\n\n.. code-block:: python\n\n    \u003e\u003e\u003e convert_units(4, DecimalUnits.TB, BinaryUnits.TB)\n    (3.637978807091713, 'TiB')\n\n**Human readable:**\n\n.. code-block:: python\n\n    \u003e\u003e\u003e amount, unit = convert_units(kubernetes_ingest_bytes_per_second)\n    \u003e\u003e\u003e 'Incoming traffic: {:.2f} {}/s'.format(amount, unit)\n    'Incoming traffic: 24.77 GiB/s'\n\nUsage\n-----\n\nJust a single function!\n\n``convert_units(n, unit=BYTE, to=None, si=False, exact=False)``\n\nConverts between and within binary and decimal units. If no ``unit``\nis specified, ``n`` is assumed to already be in bytes. If no ``to`` is\nspecified, ``n`` will be converted to the highest unit possible. If\nno ``unit`` nor ``to`` is specified, the output will be binary units\nunless ``si`` is ``True``. If ``exact`` is ``True``. the calculations\nwill use ``decimal.Decimal``.\n\n| Binary units conform to IEC standards, see:\n| `\u003chttps://en.wikipedia.org/wiki/Binary_prefix\u003e`_\n| `\u003chttps://en.wikipedia.org/wiki/IEC_80000-13\u003e`_\n| `\u003chttps://www.iso.org/standard/31898.html\u003e`_ (paywalled)\n|\n| Decimal units conform to SI standards, see:\n| `\u003chttps://en.wikipedia.org/wiki/International_System_of_Units\u003e`_\n|\n\n* Parameters\n\n  - **n** (``int`` or ``float``) - The number of ``unit``\\ s.\n  - **unit** - The unit ``n`` represents. See `types`_.\n  - **to** - The unit to convert to. See `types`_.\n  - **si** (``bool``) - Assume SI units when no ``unit`` nor ``to`` is specified.\n  - **exact** (``bool``) - Use ``decimal.Decimal`` for calculations.\n\nTypes\n^^^^^\n\nAlthough the string representations for binary units end in ``iB``,\nthe attributes do not for ease of use.\n\n+--------------+-------+-----------+\n| Type         | Short | Long      |\n+==============+=======+===========+\n| BinaryUnits  | B     | BYTE      |\n+--------------+-------+-----------+\n| BinaryUnits  | KB    | KIBIBYTE  |\n+--------------+-------+-----------+\n| BinaryUnits  | MB    | MEBIBYTE  |\n+--------------+-------+-----------+\n| BinaryUnits  | GB    | GIBIBYTE  |\n+--------------+-------+-----------+\n| BinaryUnits  | TB    | TEBIBYTE  |\n+--------------+-------+-----------+\n| BinaryUnits  | PB    | PEBIBYTE  |\n+--------------+-------+-----------+\n| BinaryUnits  | EB    | EXBIBYTE  |\n+--------------+-------+-----------+\n| BinaryUnits  | ZB    | ZEBIBYTE  |\n+--------------+-------+-----------+\n| BinaryUnits  | YB    | YOBIBYTE  |\n+--------------+-------+-----------+\n| DecimalUnits | B     | BYTE      |\n+--------------+-------+-----------+\n| DecimalUnits | KB    | KILOBYTE  |\n+--------------+-------+-----------+\n| DecimalUnits | MB    | MEGABYTE  |\n+--------------+-------+-----------+\n| DecimalUnits | GB    | GIGABYTE  |\n+--------------+-------+-----------+\n| DecimalUnits | TB    | TERABYTE  |\n+--------------+-------+-----------+\n| DecimalUnits | PB    | PETABYTE  |\n+--------------+-------+-----------+\n| DecimalUnits | EB    | EXABYTE   |\n+--------------+-------+-----------+\n| DecimalUnits | ZB    | ZETTABYTE |\n+--------------+-------+-----------+\n| DecimalUnits | YB    | YOTTABYTE |\n+--------------+-------+-----------+\n\nLicense\n-------\n\n``binary`` is distributed under the terms of both\n\n- `MIT License \u003chttps://choosealicense.com/licenses/mit\u003e`_\n- `Apache License, Version 2.0 \u003chttps://choosealicense.com/licenses/apache-2.0\u003e`_\n\nat your option.\n\nChangelog\n---------\n\nImportant changes are emphasized.\n\n1.0.1\n^^^^^\n\n- Fix syntax warning on newer versions of Python\n\n1.0.0\n^^^^^\n\n- Initial release\n\n.. _IEC: https://en.wikipedia.org/wiki/Binary_prefix\n.. _SI: https://en.wikipedia.org/wiki/International_System_of_Units\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofek%2Fbinary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofek%2Fbinary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofek%2Fbinary/lists"}