A python wrapper for libmagic
Python
Pull request Compare This branch is 127 commits behind ahupp:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
testdata
README
magic.py
setup.py
test.py

README

= python-magic =

Adam Hupp <adam at hupp.org>

Distributed under the PSF License: http://www.python.org/psf/license/

python-magic is a simple wrapper for libmagic.  libmagic identifies
file types according to their headers.  It is the core of the Unix
"file" command.


= Installation =

This module depends on libmagic to run.  It needs swig and
libmagic-dev to build.

To build and install run:

# python setup.py install

= Installation on Win32 =

You need magic1.dll from http://gnuwin32.sourceforge.net/, grab the
binaries and dependencies ZIP-file, extract magic1.dll, regex2.dll
and zlib1.dll and put it in C:\Windows\System32. You also need a 
magic file from Linux, compatible with file version 5.0.

To build and install run:

# python setup.py install

= Example Usage =

>>> import magic
>>> m = magic.Magic()
>>> m.from_file("testdata/test.pdf")
'PDF document, version 1.2'
>>> m.from_buffer(open("testdata/test.pdf").read(1024))
'PDF document, version 1.2'

# For MIME types
>>> mime = magic.Magic(mime=True)
>>> mime.from_file("testdata/test.pdf")
'application/pdf'
>>>