Ultra-lightweight pure Python package to check if a file is binary or text.
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.
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:
Has tests for these file types:
Has tests for numerous encodings.
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.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|binaryornot-0.4.3-py2.py3-none-any.whl (8.9 kB) Copy SHA256 Checksum SHA256||3.6||Wheel||Apr 12, 2017|
|binaryornot-0.4.3.tar.gz (370.9 kB) Copy SHA256 Checksum SHA256||–||Source||Apr 12, 2017|