Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Python bindings to libmagic

Project Description

# python-libmagic


# Usage

import magic

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

import magic
import magic.flags

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

mimetype = magic.from_file("/etc/passwd")
print mimetype # => "text/plain"

updated = magic.set_flags(magic.flags.MAGIC_NONE)
print updated # => True
mimetype = magic.from_file("demo.docx")
print mimetype # => "Microsoft Word 2007+"
magic.close() # don't forget about this

# Installation

`python-libmagic` works on CPython 2.7/3.3+ and PyPy.

$ apt-get install libmagic-dev
$ pip install python-libmagic

# License

Licensed under MIT license.

Release History

This version
History Node


History Node


History Node


History Node


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
(3.6 kB) Copy SHA256 Hash SHA256
Source None Jul 7, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers