Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A python wrapper for libmagic
Branch: master
Pull request Compare This branch is 75 commits behind ahupp:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


= python-magic =

Adam Hupp <adam at>

Distributed under the 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 install

= Installation on Win32 =

You need magic1.dll from, 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 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")
Something went wrong with that request. Please try again.