python-magic-bin
File type identification using libmagic binary package
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- 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.
- 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 · maintenance · safety
MIT (permissive) — MIT license is permissive; you may use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
last release 2017-10-02 (3238 days) · last repo commit 2023-11-21 · 33 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 204,568 downloads/mo, #9,604 on PyPI
Alternatives
Verify before relying
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'- 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.
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 on this page. Verify before relying on it.
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
python-magic-bin on PyPI
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.
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.
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'
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 | Not specified |
| Install friction | Medium. Platform-specific wheel |
| Runtime dependencies | None |
| Maintenance | Dormant 3,238 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 204,568 / month, #9,604 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 3 |
Evidence: python_magic_bin-0.4.14-py2.py3-none-macosx_10_6_intel.whl; python_magic_bin-0.4.14-py2.py3-none-win32.whl; python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mime type identification”
- python-magic-binIdentifies file types by examining file headers using libmagic,…
- python-magicIdentifies file types by reading file headers and checking them…
- typecodeDetects file types and MIME types using libmagic and Pygments, with…
Give your agent the search over MCP, or paste the wish link into any chat.
More Utilities packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Detects and normalizes text encoding from unknown or ambiguous sources, supporting all IANA character sets that Python's core library provides codecs for, with the ability to register custom codecs.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Pygments is a syntax highlighter that colorizes source code and text in over 500 languages and formats, outputting to HTML, LaTeX, RTF, SVG, images, or ANSI terminal sequences.
Install it if you need to display or transform source code.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
See also puremagic · pylibmagic · python-magic · libmagic · cigam · file-magic · magika · polyfile-weave · filetype · typecode-libmagic