python-magic‘s usage goes like:
>>> import magic >>> magic.from_file("testdata/test.pdf") 'PDF document, version 1.2' >>> magic.from_file("testdata/test.pdf", mime=True) 'application/pdf' >>> magic.from_buffer(open("testdata/test.pdf").read(1024)) 'PDF document, version 1.2'
Not sure the audiences would be, perhaps file managers? Which would need to know about file types. It uses ctypes to interface with libmagic, and it supports not only Linux, but also Windows via Cygwin, as well as Mac OS X via Homebrew or MacPorts.
If you know about file command, the you can expect what this library can get from libmagic.
There is a bit of history noted in its README:
Written by Adam Hupp in 2001 for a project that never got off the ground. It origionally used SWIG for the C library bindings, but switched to ctypes once that was part of the python standard library.
python-magic is written by Adam Hupp under the MIT License for both Python 2 and 3, currently git-012f8a9 (2014-05-31, post v0.4.6 (2013-10-08)).
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.