--- id: python-magic-bin version: "0.4.14" license: MIT license_treatment: permissive maintenance: dormant --- # python-magic-bin — File type identification using libmagic binary package License: permissive · Maintenance: dormant · Downloads: 204.6K/mo ## What it is and what it does python-magic-bin is a Python wrapper around libmagic, the file-type identification library that powers the Unix `file` command. It identifies files by examining their headers against a predefined database of file signatures, returning human-readable descriptions or MIME types. The package is a fork of python-magic that bundles pre-compiled libmagic binaries for Windows, macOS, and Linux, eliminating the need to install libmagic separately on those platforms. You can use it two ways: the simple functional API (magic.from_file, magic.from_buffer) for quick file identification, or the Magic class for finer control over options like MIME mode, compression detection, and character encoding. The package has no runtime dependencies beyond the bundled libmagic binaries, making it straightforward to integrate into file-processing pipelines, content-type detection systems, or validation workflows. Use it for: - Detect file types in upload handlers to validate user-submitted files without relying on extensions. - Identify MIME types for web servers or APIs serving files with correct Content-Type headers. - Analyze compressed archives by detecting both the outer format and decompressed content type. - Validate binary file integrity by confirming expected file signatures before processing. - Build content-aware file routing or filtering systems that classify files by their actual type. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Identifies file types by examining file headers using libmagic, exposing the Unix `file` command's functionality to Python with pre-built binaries for Windows, macOS, and Linux. Yes, if you need reliable file-type detection and want to avoid installing libmagic separately on Windows or macOS. The package is stable with no known vulnerabilities. However, verify compatibility with your Python version; the fork's last release was 2017-10-02 and the project is dormant. ## Install pip install python-magic-bin uv add python-magic-bin poetry add python-magic-bin ## Installing python-magic-bin Before you install: Medium install friction due to platform-specific binary wheels; the package is dormant (last release 2017-10-02, last commit 2023-11-21) but carries no known vulnerabilities. License in practice: MIT license is permissive; you may use, modify, and distribute this package freely in commercial and private projects with minimal restrictions. Quickstart: pip install python-magic-bin import magic result = magic.from_file("testdata/test.pdf") print(result) # 'PDF document, version 1.2' mime_type = magic.from_file("testdata/test.pdf", mime=True) print(mime_type) # 'application/pdf' On Windows, you may need to manually provide libmagic DLLs (magic1.dll, regex2.dll, zlib1.dll) and the magic database file; 32-bit and 64-bit builds must match your Python installation. Verify before relying: - Whether the package's dormancy (no releases since 2017-10-02) affects compatibility with modern Python versions or libmagic APIs. - Current status of the upstream python-magic library and whether this fork remains the recommended binary-packaged alternative. - Actual adoption and usage patterns given the long time since last release. ## Package facts - License: MIT (permissive) - Python support: unspecified - Install friction: medium - Maintenance: dormant - Downloads: 204.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags file type detection python, mime type identification, libmagic python wrapper, file magic number detection, binary file type recognition, file header analysis, magic database file identification, file-identification, mime-type-detection, binary-analysis [View on SkillFed](https://skillfed.io/packages/python-magic-bin) · [View on PyPI](https://pypi.org/project/python-magic-bin/)