binary
Easily convert between binary and SI units (kibibyte, kilobyte, etc.).
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.6%) to scientific vocabulary
Keywords
binary-prefix
conversion
library
python
si-units
units-of-measurement
Keywords from Contributors
version
Last synced: 6 months ago
·
JSON representation
Repository
Easily convert between binary and SI units (kibibyte, kilobyte, etc.).
Basic Info
Statistics
- Stars: 10
- Watchers: 2
- Forks: 4
- Open Issues: 1
- Releases: 1
Topics
binary-prefix
conversion
library
python
si-units
units-of-measurement
Created about 8 years ago
· Last pushed 8 months ago
Metadata Files
Readme
License
README.rst
binary
======
.. image:: https://img.shields.io/pypi/v/binary.svg?style=flat-square
:target: https://pypi.org/project/binary
:alt: Latest PyPI version
.. image:: https://github.com/ofek/binary/actions/workflows/test.yml/badge.svg
:target: https://github.com/ofek/binary/actions/workflows/test.yml
:alt: GitHub Actions
.. image:: https://img.shields.io/codecov/c/github/ofek/binary/master.svg?style=flat-square
:target: https://codecov.io/gh/ofek/binary
:alt: Codecov
.. image:: https://img.shields.io/pypi/pyversions/binary.svg?style=flat-square
:target: https://pypi.org/project/binary
:alt: Supported Python versions
.. image:: https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-9400d3.svg
:target: https://spdx.org/licenses/
:alt: License
.. image:: https://img.shields.io/github/sponsors/ofek?logo=GitHub%20Sponsors&style=social
:target: https://github.com/sponsors/ofek
:alt: GitHub sponsors
-----
``binary`` provides a bug-free and easy way to convert between and within
binary (`IEC`_) and decimal (`SI`_) units.
.. contents:: **Table of Contents**
:backlinks: none
Installation
------------
.. code-block:: bash
$ pip install binary
Examples
--------
Let's import what we need:
.. code-block:: python
>>> from binary import BinaryUnits, DecimalUnits, convert_units
**Basic conversion:**
.. code-block:: python
>>> convert_units(1536, BinaryUnits.KB, BinaryUnits.MB)
(1.5, 'MiB')
**How much actual storage your new hard drive has:**
.. code-block:: python
>>> convert_units(4, DecimalUnits.TB, BinaryUnits.TB)
(3.637978807091713, 'TiB')
**Human readable:**
.. code-block:: python
>>> amount, unit = convert_units(kubernetes_ingest_bytes_per_second)
>>> 'Incoming traffic: {:.2f} {}/s'.format(amount, unit)
'Incoming traffic: 24.77 GiB/s'
Usage
-----
Just a single function!
``convert_units(n, unit=BYTE, to=None, si=False, exact=False)``
Converts between and within binary and decimal units. If no ``unit``
is specified, ``n`` is assumed to already be in bytes. If no ``to`` is
specified, ``n`` will be converted to the highest unit possible. If
no ``unit`` nor ``to`` is specified, the output will be binary units
unless ``si`` is ``True``. If ``exact`` is ``True``. the calculations
will use ``decimal.Decimal``.
| Binary units conform to IEC standards, see:
| ``_
| ``_
| ``_ (paywalled)
|
| Decimal units conform to SI standards, see:
| ``_
|
* Parameters
- **n** (``int`` or ``float``) - The number of ``unit``\ s.
- **unit** - The unit ``n`` represents. See `types`_.
- **to** - The unit to convert to. See `types`_.
- **si** (``bool``) - Assume SI units when no ``unit`` nor ``to`` is specified.
- **exact** (``bool``) - Use ``decimal.Decimal`` for calculations.
Types
^^^^^
Although the string representations for binary units end in ``iB``,
the attributes do not for ease of use.
+--------------+-------+-----------+
| Type | Short | Long |
+==============+=======+===========+
| BinaryUnits | B | BYTE |
+--------------+-------+-----------+
| BinaryUnits | KB | KIBIBYTE |
+--------------+-------+-----------+
| BinaryUnits | MB | MEBIBYTE |
+--------------+-------+-----------+
| BinaryUnits | GB | GIBIBYTE |
+--------------+-------+-----------+
| BinaryUnits | TB | TEBIBYTE |
+--------------+-------+-----------+
| BinaryUnits | PB | PEBIBYTE |
+--------------+-------+-----------+
| BinaryUnits | EB | EXBIBYTE |
+--------------+-------+-----------+
| BinaryUnits | ZB | ZEBIBYTE |
+--------------+-------+-----------+
| BinaryUnits | YB | YOBIBYTE |
+--------------+-------+-----------+
| DecimalUnits | B | BYTE |
+--------------+-------+-----------+
| DecimalUnits | KB | KILOBYTE |
+--------------+-------+-----------+
| DecimalUnits | MB | MEGABYTE |
+--------------+-------+-----------+
| DecimalUnits | GB | GIGABYTE |
+--------------+-------+-----------+
| DecimalUnits | TB | TERABYTE |
+--------------+-------+-----------+
| DecimalUnits | PB | PETABYTE |
+--------------+-------+-----------+
| DecimalUnits | EB | EXABYTE |
+--------------+-------+-----------+
| DecimalUnits | ZB | ZETTABYTE |
+--------------+-------+-----------+
| DecimalUnits | YB | YOTTABYTE |
+--------------+-------+-----------+
License
-------
``binary`` is distributed under the terms of both
- `MIT License `_
- `Apache License, Version 2.0 `_
at your option.
Changelog
---------
Important changes are emphasized.
1.0.2
^^^^^
- Perform floor division when explicitly converting to bytes
- Support negative values
1.0.1
^^^^^
- Fix syntax warning on newer versions of Python
1.0.0
^^^^^
- Initial release
.. _IEC: https://en.wikipedia.org/wiki/Binary_prefix
.. _SI: https://en.wikipedia.org/wiki/International_System_of_Units
Owner
- Name: Ofek Lev
- Login: ofek
- Kind: user
- Location: Knowhere
- Company: @datadog
- Website: https://ofek.dev
- Repositories: 302
- Profile: https://github.com/ofek
I like developing beautiful APIs.
GitHub Events
Total
- Create event: 4
- Issues event: 1
- Release event: 2
- Watch event: 1
- Issue comment event: 2
- Push event: 7
- Pull request review comment event: 14
- Pull request review event: 10
- Pull request event: 5
- Fork event: 1
Last Year
- Create event: 4
- Issues event: 1
- Release event: 2
- Watch event: 1
- Issue comment event: 2
- Push event: 7
- Pull request review comment event: 14
- Pull request review event: 10
- Pull request event: 5
- Fork event: 1
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Ofek Lev | o****r@g****m | 23 |
| Jon Dufresne | j****e@g****m | 9 |
| Pierre Gimalac | p****c@g****m | 1 |
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 1
- Total pull requests: 11
- Average time to close issues: N/A
- Average time to close pull requests: about 5 hours
- Total issue authors: 1
- Total pull request authors: 2
- Average comments per issue: 2.0
- Average comments per pull request: 0.82
- Merged pull requests: 10
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: about 4 hours
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.5
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- anilkumarmyla (1)
Pull Request Authors
- jdufresne (9)
- pgimalac (4)
- ofek (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 379,703 last-month
- Total docker downloads: 18,284,211
- Total dependent packages: 2
- Total dependent repositories: 57
- Total versions: 4
- Total maintainers: 1
pypi.org: binary
- Homepage: https://github.com/ofek/binary
- Documentation: https://binary.readthedocs.io/
- License: apache-2.0
-
Latest release: 1.0.2
published 8 months ago
Rankings
Docker downloads count: 0.5%
Downloads: 1.2%
Dependent repos count: 2.0%
Dependent packages count: 3.1%
Average: 6.9%
Forks count: 16.9%
Stargazers count: 17.7%
Maintainers (1)
Last synced:
6 months ago
Dependencies
.github/workflows/build.yml
actions
- actions/checkout v4 composite
- actions/download-artifact v4 composite
- actions/setup-python v5 composite
- actions/upload-artifact v4 composite
- pypa/gh-action-pypi-publish v1.10.2 composite
- pypa/hatch install composite
.github/workflows/lint.yml
actions
- actions/checkout v3 composite
- actions/setup-python v4 composite
.github/workflows/test.yml
actions
- actions/checkout v3 composite
- actions/setup-python v4 composite
- codecov/codecov-action v3 composite
pyproject.toml
pypi
requirements.txt
pypi