IsBinary

raw JSON →
1.0.1 verified Sat May 09 auth: no python

A lightweight pure Python package to check if a file is binary or text (fork of binaryornot). Current version 1.0.1, released April 2023. Uses heuristic scanning of a configurable chunk of bytes.

pip install isbinary
error ModuleNotFoundError: No module named 'binaryornot'
cause The old package binaryornot is replaced by isbinary.
fix
Install isbinary and update imports: from isbinary import is_binary_file.
error AttributeError: module 'binaryornot.check' has no attribute 'is_binary'
cause The package was renamed; import path is different.
fix
Use from isbinary import is_binary_file.
error ImportError: cannot import name 'is_binary' from 'isbinary'
cause Function was renamed from is_binary to is_binary_file in v1.0.0.
fix
Use from isbinary import is_binary_file and call is_binary_file(path).
breaking In v1.0.0 the package name changed from binaryornot to isbinary. All imports must be updated.
fix Replace `from binaryornot.check import is_binary` with `from isbinary import is_binary_file`.
breaking The function name changed from `is_binary` to `is_binary_file` in v1.0.0.
fix Change all calls from `is_binary(path)` to `is_binary_file(path)`.
gotcha The default chunk size increased from 1024 to 2048 bytes. This may affect detection of very small files or performance.
fix If needed, adjust chunk size with the `chunk_size` parameter: `is_binary_file(path, chunk_size=1024)`.
gotcha Python 2 support was removed. Only Python 3.8+ is supported.
fix Ensure you run on Python 3.8 or later.

Basic usage to detect binary vs text file.

from isbinary import is_binary_file

result = is_binary_file('path/to/file')
print(result)  # True if binary, False if text

# Or via CLI: python -m isbinary path/to/file