libmagic
libmagic bindings
What it is and what it does
libmagic is a Python wrapper around the libmagic C library, providing file type and MIME type detection through ctypes. It allows you to query the type of a file by reading its magic bytes—the identifying patterns at the start of a file—rather than relying on file extensions. The package is a thin binding with no runtime Python dependencies, relying entirely on the system-installed libmagic library.
The package has been abandoned since its single release in 2012 and receives no maintenance. While it may still work on systems with libmagic installed, it carries significant risk: no bug fixes, no Python version support updates, and no response to security issues. The GPL v3 copyleft license also imposes source-code disclosure requirements on any project that uses it.
Use it for:
- Detect file types by content rather than extension in legacy systems still using this binding.
- Identify MIME types for uploaded files in web applications that cannot upgrade dependencies.
- Analyze file format in security or forensics tools where libmagic integration is already established.
- Validate file integrity by checking magic bytes in batch processing scripts with minimal dependencies.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Python bindings to the libmagic library for file type detection and MIME type identification using ctypes.
No. The package is abandoned (last release 2012-03-02, no maintenance since), carries high install friction (requires compiled libmagic), and is licensed under GPL v3 copyleft. Modern alternatives like `python-magic` or `python-magic-bin` are maintained and provide the same functionality. Install this only if you are maintaining legacy code that already depends on it and cannot migrate.
Install
libmagic on PyPI
pip
pip install libmagicuv
uv add libmagicpoetry
poetry add libmagicInstalling libmagic
Before you install
High install friction due to a compiled system dependency (libmagic-1.0.tar.gz). The package is abandoned—last release was 2012-03-02 with no commits or maintenance activity since. Use only if you have a specific reason to prefer this binding over maintained alternatives.
License in practice
Licensed under GPL v3 (copyleft). Any code that imports this package must comply with GPL v3 terms, including potential source code disclosure obligations if distributed.
Quickstart
import libmagic
# Requires libmagic system library installed
magic_instance = libmagic.open()
file_type = magic_instance.file('/path/to/file')
magic_instance.close()
libmagic system library must be installed on the system; ctypes requires the compiled libmagic shared object to be available at runtime.
Verify before relying
- Whether libmagic system dependency is available on modern operating systems and package managers.
- Compatibility with Python versions beyond those available in 2012; requires_python is unspecified.
- Whether the ctypes binding handles edge cases or errors that modern file-type libraries address.
Package facts
| License | GPL v3 (copyleft) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 5,278 days since the last release |
| First released | |
| Downloads | 127,815/month — #11,729 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: libmagic-1.0.tar.gz
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
file-magicfile-magic provides a Python interface to…
permissive · top 15,000 on PyPI
python-magicIdentifies file types by reading file headers…
permissive · top 1,000 on PyPI
python-magic-binIdentifies file types by examining file headers…
permissive · top 15,000 on PyPI
typecodeDetects file types and MIME types using…
permissive · top 15,000 on PyPI
polyfile-weaveIdentifies and maps the semantic and syntactic…
permissive · top 5,000 on PyPI
cigamDetects and reports file types, MIME types, and…
permissive · top 15,000 on PyPI
puremagicIdentifies file types by analyzing magic…
permissive · top 5,000 on PyPI
filetypeInfers file type and MIME type by examining…
permissive · top 1,000 on PyPI
typecode-libmagicProvides a prebuilt native libmagic binary and…
copyleft · top 15,000 on PyPI
magikaMagika identifies file types using deep…
permissive · top 5,000 on PyPI