pylibmagic
scikit-build project with CMake for compiling libmagic
What it is and what it does
pylibmagic is a minimal Python package that bundles pre-compiled libmagic libraries and registers them so they become available to dependent packages. It ships compiled binaries for multiple platforms (macOS, Linux, musl) and architectures using CMake and scikit-build, addressing the common ImportError that occurs when libmagic is not installed on the system.
The package is designed as a lightweight shim: install it, and the bundled libraries become available. It depends only on importlib-resources and typing-extensions, keeping the footprint minimal. It supports Python 3.7 through 3.12 and is classified as Beta-stage software.
Use it for:
- Deploying applications in containerized or CI/CD environments where system package managers are unavailable or restricted.
- Distributing Python applications that need file-type detection without requiring end-users to install system libraries.
- Cross-platform development where developers use different operating systems and want consistent library availability.
- Scientific or research workflows that depend on file-type detection in sandboxed or minimal-dependency environments.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides pre-compiled libmagic libraries bundled with Python, solving the missing system dependency problem that typically breaks python-magic imports.
Yes, if you need to resolve libmagic import errors or distribute applications without system dependencies. The permissive license, active maintenance, and platform-specific wheels make it a straightforward solution to a real problem. The gap since the last release (2023-10-19) is worth verifying against your target Python and platform before production use.
Install
pylibmagic on PyPI
pip
pip install pylibmagicuv
uv add pylibmagicpoetry
poetry add pylibmagicInstalling pylibmagic
Before you install
Medium install friction due to platform-specific wheels across macOS (x86_64 and arm64), Linux (x86_64 and aarch64), and musl variants. Repository is active with recent commits and stable maintenance.
License in practice
Permissive BSD license allows commercial and private use without restriction; no copyleft obligations.
Quickstart
$ python3 -m pip install pylibmagic
import pylibmagic
import importlib-resources
import typing-extensions
Requires Python 3.7 or later; platform-specific wheels available for macOS (Intel and ARM), Linux (glibc and musl), and aarch64 architectures.
Verify before relying
- Whether pylibmagic works correctly as a drop-in solution for the libmagic import error described in the documentation.
- Performance characteristics and feature compatibility with system-installed libmagic.
- Real-world success rate in containerized or CI/CD environments where system dependencies are unavailable.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 2 — importlib-resources, typing-extensions |
| Maintenance | actively maintained — 1,030 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 330,454/month — #7,536 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pylibmagic-0.5.0-py3-none-macosx_10_9_x86_64.whl; pylibmagic-0.5.0-py3-none-macosx_11_0_arm64.whl; pylibmagic-0.5.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; pylibmagic-0.5.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; pylibmagic-0.5.0-py3-none-musllinux_1_1_aarch64.whl; pylibmagic-0.5.0-py3-none-musllinux_1_1_x86_64.whl
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
python-magic-binIdentifies file types by examining file headers…
permissive · top 15,000 on PyPI
python-magicIdentifies file types by reading file headers…
permissive · top 1,000 on PyPI
file-magicfile-magic provides a Python interface to…
permissive · top 15,000 on PyPI
typecode-libmagicProvides a prebuilt native libmagic binary and…
copyleft · top 15,000 on PyPI
puremagicIdentifies file types by analyzing magic…
permissive · top 5,000 on PyPI
libmagicProvides Python bindings to the libmagic…
copyleft · top 15,000 on PyPI
libuuuPython wrapper for libuuu, a library for NXP…
permissive · top 15,000 on PyPI
scikit-buildscikit-build bridges setuptools and CMake to…
permissive · top 5,000 on PyPI
typecodeDetects file types and MIME types using…
permissive · top 15,000 on PyPI
epicscorelibsProvides compiled EPICS Core libraries and…
unclear · top 15,000 on PyPI