Skip to main content

BinaryOrNot

https://img.shields.io/pypi/v/binaryornot.svg?style=flat Documentation Status Updates

Ultra-lightweight pure Python package to guess whether a file is binary or text, using a heuristic similar to Perl’s pp_fttext and its analysis by @eliben.

Status

It works, and people are using this package in various places. But it doesn’t cover all edge cases yet.

The code could be improved. Pull requests welcome! As of now, it is based on these snippets, but that may change:

Features

Has tests for these file types:

  • Text: .txt, .css, .json, .svg, .js, .lua, .pl, .rst

  • Binary: .png, .gif, .jpg, .tiff, .bmp, .DS_Store, .eot, .otf, .ttf, .woff, .rgb

Has tests for numerous encodings.

Why?

You may be thinking, “I can write this in 2 lines of code?!”

It’s actually not that easy. Here’s a great article about how Perl’s heuristic to guess file types works: http://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/

And that’s just where we started. Over time, we’ve found more edge cases and our heuristic has gotten more complex.

Also, this package saves you from having to write and thoroughly test your code with all sorts of weird file types and encodings, cross-platform.

Builds

Linux (Ubuntu 12.04 LTS Server Edition 64 bit):

https://img.shields.io/travis/audreyr/binaryornot/master.svg

Windows (Windows Server 2012 R2 (x64)):

https://img.shields.io/appveyor/ci/audreyr/binaryornot/master.svg

Credits

History

0.4.3 (2017-04-13)

0.4.2 (2017-04-12)

0.4.0 (2015-08-21)

  • Enhanced detection for some binary streams and UTF texts. (#10, 11) Thanks @pombredanne.

  • Set up Appveyor for continuous testing on Windows. Thanks @pydanny.

  • Update link to Perl source implementation. (#9) Thanks @asmeurer @pombredanne @audreyr.

  • Handle UnicodeDecodeError in check. (#12) Thanks @DRMacIver.

  • Add very simple Hypothesis based tests. (#13) Thanks @DRMacIver.

  • Use setup to determine requirements and remove redundant requirements.txt. (#14) Thanks @hackebrot.

  • Add documentation status badge to README.rst. (#15) Thanks @hackebrot.

  • Run tox in travis.yml. Add pypy and Python 3.4 to tox environments. (#16) Thanks @hackebrot @pydanny.

  • Handle LookupError when detecting encoding. (#17) Thanks @DRMacIver.

0.3.0 (2014-05-05)

  • Include tests, docs in source package. (#6) Thanks @vincentbernat.

  • Drop unnecessary shebangs and executable bits. (#8) Thanks @scop.

  • Generate string of printable extended ASCII bytes only once. (#7) Thanks @scop.

  • Make number of bytes to read parametrizable. (#7) Thanks @scop.

0.2.0 (2013-09-22)

  • Complete rewrite of everything. Thanks @ncoghlan.

0.1.1 (2013-08-17)

  • Tests pass under Python 2.6, 2.7, 3.3, PyPy.

0.1.0 (2013-08-17)

  • First release on PyPI.

Metadata

Release files for binaryornot 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for binaryornot 0.4.3
File Size Uploaded
binaryornot-0.4.3.tar.gz 370.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for binaryornot 0.4.3
File Interpreter ABI Platform
binaryornot-0.4.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 379.8 kB

Release files / binaryornot-0.4.3.tar.gz

Download URL binaryornot-0.4.3.tar.gz
Size 370.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d359566c1744526be6ea47e56bbc6f506a76cabdd49c09f6847520594f1b309e
BLAKE2b-256 checksum
How to use checksums
1200cc37b0a1eea6eefcb4574036a74fde3ea9f45d302d5f2eee7b67c832ceb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / binaryornot-0.4.3-py2.py3-none-any.whl

Download URL binaryornot-0.4.3-py2.py3-none-any.whl
Size 8.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
475318ab4983dc1746b788c6cdf4399fef23bcd624eb2800b402f508dbe5a7dd
BLAKE2b-256 checksum
How to use checksums
5830c817b7f213f09f4b9e049061283d56875636d26d64d62ee626f06c862f72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.6.0

2 release files

0.5.0

2 release files

0.4.4

2 release files

This release

0.4.3 This release

2 release files

0.4.2

2 release files

0.4.0

2 release files

0.3.0

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page