Registry / data / binaryornot

binaryornot

JSON →
library0.6.0pypypi✓ verified 25d ago

binaryornot is an ultra-lightweight, pure Python package designed to check if a file is binary or text using simple heuristics. It is currently at version 0.6.0 and appears to have a slow but steady release cadence, primarily for Python version compatibility updates.

pip install binaryornot
INSTALL
IMPORT
SIG · BINARYORNOT
B
binaryornot
datapythonv0.6.0
Install
1.6s avg
Import
83ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.084s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.082s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

is_binary
from binaryornot.check import is_binary
from binaryornot import is_binary

This quickstart demonstrates how to import and use the `is_binary` function to check both a generated text file and a generated binary file. It covers file creation, checking, and cleanup.

import os import tempfile from binaryornot.binary import is_binary # Create a dummy text file with tempfile.NamedTemporaryFile(delete=False, mode='w', encoding='utf-8') as f: f.write('This is a text file.\nHello World.') text_filepath = f.name # Create a dummy binary file (e.g., with null bytes) with tempfile.NamedTemporaryFile(delete=False, mode='wb') as f: f.write(b'\x00\x01\x02\x03This is a binary file.') binary_filepath = f.name # Check the files print(f"'{text_filepath}' is binary: {is_binary(text_filepath)}") print(f"'{binary_filepath}' is binary: {is_binary(binary_filepath)}") # Clean up temporary files os.remove(text_filepath) os.remove(binary_filepath)
Debug
Known issues
gotchaThe `is_binary` function uses heuristics (checking for null bytes and specific control characters within the initial file chunk) rather than a definitive file format analysis. This means it may occasionally misclassify certain text files with unusual encodings or binary files lacking typical binary signatures in the sampled portion.
fix
Understand that the detection is heuristic-based. For critical use cases where absolute certainty is required, consider using libraries that perform deeper file format analysis (e.g., python-magic) or explicit magic number checks if the expected format is known.
affects: All versions
gotchaThe `is_binary` function directly interacts with the filesystem. It will raise standard Python I/O exceptions such as `FileNotFoundError` if the specified path does not exist, or `PermissionError` if the file cannot be opened for reading.
fix
Always wrap calls to `is_binary` within `try...except` blocks to gracefully handle potential file system errors. Ensure the file path exists and the application has read permissions before invoking the function.
affects: All versions
gotchaIncorrect import path: A common mistake is to attempt to import `is_binary` directly from the top-level `binaryornot` package. However, the function resides in the `binary` submodule.
fix
Use the correct import statement: `from binaryornot.binary import is_binary`.
affects: All versions
breakingThe `ModuleNotFoundError: No module named 'binaryornot.binary'` indicates that the `binaryornot` package is not installed in the current Python environment or is not accessible. This error will occur even when using the correct import path `from binaryornot.binary import is_binary` if the package itself is missing.
fix
Ensure the `binaryornot` package is installed using `pip install binaryornot` in the Python environment where the script is executed. Verify the package is listed when running `pip freeze` or `pip list`.
affects: All versions
Upgrade
Version history
0.6.0latest on PyPI · released Mar 8, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
binaryornot — pip install binaryornot · libregistry