python-magic
File type identification using libmagic
Install
python-magic on PyPI
pip
pip install python-magicuv
uv add python-magicpoetry
poetry add python-magicPackage facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 1,528 days since the last release |
| Last repo commit | |
| First released | |
| Popularity | one of the top 1,000 most-downloaded packages on PyPI (30-day window, as of 2026-08-13) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-13) |
Evidence: python_magic-0.4.27-py2.py3-none-any.whl
Keywords: mime, magic, file
About python-magic
from the package's own PyPI description — quoted content, verbatim
python-magic
PyPI version (image) Build Status (image) Join the chat at https://gitter.im/ahupp/python-magic (image)
python-magic is a Python interface to the libmagic file type
identification library. libmagic identifies file types by checking
their headers according to a predefined list of file types. This
functionality is exposed to the command line by the Unix command
file.
Usage
>>> import magic
>>> magic.from_file("testdata/test.pdf")
'PDF document, version 1.2'
# recommend using at least the first 2048 bytes, as less can produce incorrect identification
>>> magic.from_buffer(open("testdata/test.pdf", "rb").read(2048))
'PDF document, version 1.2'
>>> magic.from_file("testdata/test.pdf", mime=True)
'application/pdf'
There is also a Magic class that provides more direct control,
including overriding the magic...
Read as markdown · JSON record · Source repository · Homepage
Similar packages
permissive · top 1,000 on PyPI
chardetpermissive · top 1,000 on PyPI
ruamel.yamlpermissive · top 1,000 on PyPI
xxhashpermissive · top 1,000 on PyPI
pypdfium2permissive · top 1,000 on PyPI
SQLAlchemypermissive · top 100 on PyPI
nbconvertpermissive · top 1,000 on PyPI
pymupdfagpl · top 1,000 on PyPI
pymupdf-layoutagpl · top 1,000 on PyPI
pdfplumberpermissive · top 1,000 on PyPI