This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

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

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.

Credits

History

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 enviroments. (#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.
Release History

Release History

0.4.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
binaryornot-0.4.0-py2.py3-none-any.whl (8.2 kB) Copy SHA256 Checksum SHA256 3.4 Wheel Aug 22, 2015
binaryornot-0.4.0.tar.gz (370.3 kB) Copy SHA256 Checksum SHA256 Source Aug 22, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting