Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

CFFI bindings for libmagic.

Project description

CFFI bindings for libmagic.

  • Free software: MIT License


pip install file


from file import Magic

with Magic() as magic:
    print(magic.buffer("hello")) # => "text/plain"

from file import magic_buffer, magic_file, magic_setflags

magic = Magic()
mimetype = magic_buffer("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
print(mimetype) # => "image/png"

mimetype = magic_file("/etc/passwd")
print(mimetype) # => "text/plain"

from file import MAGIC_NONE
mimetype = magic_file("demo.docx")
print(mimetype) # => "Microsoft Word 2007+"
magic.close() # don't forget about this


0.3.0 (2017-11-03)

  • Remove magic_version - not available in old
  • Remove magic object - will break import if there’s a load failure.

0.2.1 (2017-11-02)

  • Release without wheels.

0.2.0 (2017-11-02)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
file-0.3.0.tar.gz (15.8 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page