Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

File type identification using libmagic

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 docs
Octocat-spinner-32 magic
Octocat-spinner-32 requirements
Octocat-spinner-32 tests
Octocat-spinner-32 .coveragerc
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 CONTRIBUTORS
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.rst


filemagic is a ctypes wrapper for libmagic, the library that supports the file command on most Unix systems. The package provides a simple Python API for identifying files using the extensive database of magic strings that ships with libmagic.

filemagic has been tested against libmagic 5.11. It supports both Python2 and Python3, as well as CPython and PyPy.

Current build status Coverage status Latest PyPI version


Below is a short snippet of code showing how to use filemagic to identifying this README file.

>>> import magic
>>> with magic.Magic() as m:
...     m.id_filename('')
'ASCII text'

It is recommended that magic.Magic be used with a context manager (the with statement) to avoid leaking resources from libmagic when instances go out of scope. Otherwise the close() method must be called explicitly.

Further Reading

Refer to the filemagic documenation for further references.

Something went wrong with that request. Please try again.