Registry / serialization / binary

binary

JSON →
library1.0.2pypypi✓ verified 85d ago

The 'binary' library (ofek/binary) provides a straightforward and reliable way to convert between binary (IEC) and decimal (SI) units. It is currently at version 1.0.2, with releases driven by bug fixes and new features, maintaining an active development status.

pip install binary
INSTALL
IMPORT
SIG · BINARY
B
binary
serializationpythonv1.0.2
Install
1.7s avg
Import
16ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.017s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.7s · import 0.015s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BinaryUnits
from binary import BinaryUnits
DecimalUnits
from binary import DecimalUnits
convert_units
from binary import convert_units

Demonstrates basic unit conversion, calculating actual storage from advertised decimal units, and generating human-readable unit representations.

from binary import BinaryUnits, DecimalUnits, convert_units # Basic conversion from KB to MB (binary units) amount, unit = convert_units(1536, BinaryUnits.KB, BinaryUnits.MB) print(f"1536 KB is {amount} {unit}") # How much actual storage your new hard drive has (Decimal TB to Binary TiB) amount, unit = convert_units(4, DecimalUnits.TB, BinaryUnits.TB) print(f"4 Decimal TB is {amount:.2f} {unit}") # Human readable output (converts to highest possible unit) kubernetes_ingest_bytes_per_second = 26666666666 # Example large number of bytes amount, unit = convert_units(kubernetes_ingest_bytes_per_second) print(f"Incoming traffic: {amount:.2f} {unit}/s")
Debug
Known issues
breakingVersion 1.0.2 introduced a change where explicit conversion to bytes now performs floor division. This might alter results for some calculations compared to prior versions.
fix
Review any code explicitly converting units to bytes and verify that floor division provides the expected results. Adjust logic if rounding behavior has changed unexpectedly.
affects: >=1.0.2
gotchaThe library differentiates between binary (IEC, e.g., KiB, MiB) and decimal (SI, e.g., KB, MB) units. Misunderstanding these standards can lead to incorrect calculations, especially when comparing advertised storage (SI) with actual usable space (IEC).
fix
Always explicitly specify `BinaryUnits` or `DecimalUnits` to avoid ambiguity. Refer to IEC 80000-13 and SI standards for clarity if unsure.
affects: all
gotchaWhen `convert_units` is called without specifying a `unit` or `to` parameter, it defaults to assuming `n` is in bytes and converts to the highest possible binary unit. If `si=True` is passed, it converts to the highest SI unit. Ensure these defaults align with your intended conversion.
fix
For explicit control, always provide both the `unit` and `to` arguments. If relying on automatic conversion, be mindful of the default behavior for binary vs. SI units.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'binary'
The 'binary' library has not been installed in your Python environment or the Python interpreter cannot find it in its search path.
fix
Install the library using pip: `pip install binary`
ValueError: invalid literal for int() with base 2: '1012'
You attempted to convert a string that contains characters other than '0' or '1' when specifying the `from_unit` as `binary.BINARY`. The `binary.convert` function expects a valid binary string for this conversion.
fix
Ensure the input string contains only '0' and '1' when converting from binary: `binary.convert('1010', from_unit=binary.BINARY, to_unit=binary.DECIMAL)`
TypeError: 'int' object is not iterable
This error occurs when a function expects an iterable (like a string for binary representation) but receives an integer, or vice versa, leading to incorrect internal processing by the library. For example, trying to convert from 'BINARY' unit with an integer input.
fix
Provide the correct data type for the specified `from_unit`. If `from_unit` is `binary.BINARY`, the `value` must be a string; if `from_unit` is `binary.DECIMAL`, the `value` must be an integer: `binary.convert('1010', from_unit=binary.BINARY, to_unit=binary.DECIMAL)` or `binary.convert(10, from_unit=binary.DECIMAL, to_unit=binary.BINARY)`
AttributeError: module 'binary' has no attribute 'some_nonexistent_function'
You are trying to call a function or access an attribute that does not exist within the 'binary' module. This often happens due to typos or misunderstanding the available API.
fix
Consult the library's documentation to ensure you are using the correct function names and attributes, e.g., `binary.convert` for unit conversion.
Upgrade
Version history
1.0.2latest on PyPI · released Jun 11, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
1
Resources
binary — pip install binary · libregistry