Skip to main content

BinaryOrNot

https://badge.fury.io/py/binaryornot.png https://travis-ci.org/audreyr/binaryornot.png?branch=master https://pypip.in/d/binaryornot/badge.png

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 I’m 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: .css, .json, .txt, .svg

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

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 perldoc’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/

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

Credits

History

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.3.0

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.3.0
File Size Uploaded
binaryornot-0.3.0.tar.gz 217.6 kB Details

Release files / binaryornot-0.3.0.tar.gz

Download URL binaryornot-0.3.0.tar.gz
Size 217.6 kB
Tags Source
SHA-256 checksum
How to use checksums
83bc656b147983da8755c7b1e1323825d29a318ee437f91d210b16b1ec8bacf4
BLAKE2b-256 checksum
How to use checksums
da6afe777cc15ac20312877418277e161ee9df2dadef1341107dd3337d98025a
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

0.4.3

2 release files

0.4.2

2 release files

0.4.0

2 release files

This release

0.3.0 This release

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