skillfed

pylibmagic

scikit-build project with CMake for compiling libmagic

pylibmagic v0.5.0 330.5K downloads/30d#7,536 on PyPI12
Permissive license Active released

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 pylibmagic

uv

uv add pylibmagic

poetry

poetry add pylibmagic

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Scientific/Engineering

Tags

libmagic python bundledpython-magic dependency fixfile type detection librarymagic library python wrappersystem library bundling pythonlibmagic precompiled wheels
file-type-detectionsystem-library-bundling

More Scientific/Engineering packages