BinaryOrNot
Python library and CLI tool to check if a file is binary or text. Zero dependencies.
from binaryornot.check import is_binary
is_binary("image.png") # True
is_binary("README.md") # False
is_binary("data.sqlite") # True
is_binary("report.csv") # False
$ binaryornot image.png
True
Install
pip install binaryornot
Why not just check for null bytes?
That's the first thing everyone tries. It works until it doesn't:
- A UTF-16 text file is full of null bytes. Your tool thinks it's binary and corrupts it.
- A Big5 or GB2312 text file has high-ASCII bytes everywhere. Looks binary by byte ratios alone.
- A font file (.woff, .eot) is clearly binary but might not have null bytes in the first chunk.
BinaryOrNot reads the first 128 bytes and runs them through a trained decision tree that considers byte ratios, Shannon entropy, encoding validity, BOM detection, and more. It handles all the edge cases above correctly, with zero dependencies.
Tested against 37 text encodings and 49 binary formats, verified by parametrized tests driven from coverage CSVs.
API
One function:
from binaryornot.check import is_binary
is_binary(filename) # returns True or False
There's also is_binary_string() if you already have bytes:
from binaryornot.helpers import is_binary_string
is_binary_string(b"\x00\x01\x02") # True
is_binary_string(b"hello world") # False
Full documentation covers the detection algorithm in detail.
Credits
Created by Audrey Roy Greenfeld.
Release files for binaryornot 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| binaryornot-0.6.0.tar.gz | 478.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| binaryornot-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 492.9 kB
Release files / binaryornot-0.6.0.tar.gz
| Download URL | binaryornot-0.6.0.tar.gz |
|---|---|
| Size | 478.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc8d57cfa71d74ff8c28a7726734d53a851d02fad9e3a5581fb807f989f702f0
|
|
BLAKE2b-256 checksum How to use checksums |
86724755b85101f37707c71526a301c1203e413c715a0016ecb592de3d2dcfff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 8, 2026.
Transparency logRelease files / binaryornot-0.6.0-py3-none-any.whl
| Download URL | binaryornot-0.6.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
900adfd5e1b821255ba7e63139b0396b14c88b9286e74e03b6f51e0200331337
|
|
BLAKE2b-256 checksum How to use checksums |
cd0c31cfaa6b56fe23488ecb993bc9fc526c0d84d89607decdf2a10776426c2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 8, 2026.
Transparency log