No project description provided
Project description
binary provides a bug-free and easy way to convert between and within binary (IEC) and decimal (SI) units.
Installation
binary is distributed on PyPI as a universal wheel and is available on Linux/macOS and Windows and supports Python 2.7/3.5+ and PyPy.
$ pip install binary
Examples
Let’s import what we need:
>>> from binary import BinaryUnits, DecimalUnits, convert_units
Basic conversion:
>>> convert_units(1536, BinaryUnits.KB, BinaryUnits.MB)
(1.5, 'MiB')
How much actual storage your new hard drive has:
>>> convert_units(4, DecimalUnits.TB, BinaryUnits.TB)
(3.637978807091713, 'TiB')
Human readable:
>>> 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.
Parameters
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
at your option.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file binary-1.0.0.tar.gz
.
File metadata
- Download URL: binary-1.0.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ec010e58f7331ebc8bc9638dbe6c66d635de60d5818b0723bef4dead0ec28a6 |
|
MD5 | 930448e9b4a275f53dde8be721b8c7b7 |
|
BLAKE2b-256 | 7a09403408a5908f0af33f454c3f825c9cbb85ce7c1648594e81925de1d9e0d5 |
File details
Details for the file binary-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: binary-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1b61f3a5c002717d1a28e4d9d2dc8acbc9d6b12baf7b1e4ab25d743da97e323 |
|
MD5 | 5c2e13ffe1efc0b800044ce290dbeffe |
|
BLAKE2b-256 | b4ba37de520e4870635793164a3d6861d98357d4e43aa6ce244327183ccaa3cb |