skillfed

libmagic

libmagic bindings

libmagic v1.0 127.8K downloads/30d#11,729 on PyPI
Copyleft license GPL v3 Abandoned released

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 libmagic

uv

uv add libmagic

poetry

poetry add libmagic

Installing 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

Development Status :: 4 - BetaEnvironment :: ConsoleEnvironment :: Web EnvironmentIntended Audience :: DevelopersLicense :: OSI Approved :: GNU General Public License (GPL)Operating System :: OS IndependentProgramming Language :: PythonTopic :: SecurityTopic :: Software Development :: Libraries :: Python Modules

Tags

file type detection pythonlibmagic bindingsmime type identificationfile magic number detectionctypes file analysisfile format recognition
abandonedfile-type-detectionctypes-binding

More Python Modules packages