Skip to content
File type identification using libmagic
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
magic Better warning message when implicitly closing Feb 4, 2014
requirements Build and upload Python wheel packages to PyPI Feb 4, 2014
tests Update Python magic strings May 29, 2013
.coveragerc
.travis.yml Further coverage report tuning May 30, 2013
CHANGELOG Build and upload Python wheel packages to PyPI Feb 4, 2014
CONTRIBUTORS Reformat new CONTRIBUTORS file. Dec 18, 2012
LICENSE Update copyright year in LICENSE and docs Jan 6, 2013
MANIFEST.in Fix CONTRIBUTORS include in MANIFEST.in Jan 22, 2013
Makefile Build and upload Python wheel packages to PyPI Feb 4, 2014
README.rst Add coverage report badge to README May 30, 2013
setup.py Discontinue use of distribute_setup.py May 29, 2013

README.rst

filemagic

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

Example

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('setup.py')
...
'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.

You can’t perform that action at this time.