Registry / serialization / python-magic-bin

python-magic-bin

JSON →
library0.4.14pypypiunverified

python-magic-bin is a Python wrapper for `libmagic`, the file type identification library. Unlike the original `python-magic` package, `python-magic-bin` bundles the `libmagic` binary and its associated magic database, making it easier to install and use, especially on platforms like Windows where `libmagic` is not natively available. It currently stands at version 0.4.14 and has a slow release cadence, primarily for bug fixes or compatibility updates.

pip install python-magic-bin
INSTALL
IMPORT
SIG · PYTHON-MAGIC-BIN
P
python-magic-bin
serializationpythonv0.4.14
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Magic
import magic

Demonstrates how to import and use `python-magic-bin` to identify the MIME type of a local file. The `magic.Magic()` constructor is used, typically with `mime=True` to get standard MIME types.

import magic import os # Create a dummy file for demonstration with open('test_file.txt', 'w') as f: f.write('This is a test file.') # Instantiate Magic to get MIME types m = magic.Magic(mime=True) # Identify a local file file_path = 'test_file.txt' file_type = m.from_file(file_path) print(f"File '{file_path}' is of type: {file_type}") # Clean up the dummy file os.remove(file_path)
Debug
Known issues
gotchaConfusion with `python-magic` (without `-bin`). `python-magic-bin` bundles the `libmagic` library, making installation easier, especially on Windows. The original `python-magic` requires `libmagic` to be installed separately via your system's package manager (e.g., `apt-get install libmagic-dev` on Debian/Ubuntu). Using both or installing the wrong one is a common source of errors.
fix
Ensure you explicitly install either `python-magic` or `python-magic-bin`, but not both if you don't understand their differences. For easier setup, especially on Windows, `python-magic-bin` is usually preferred.
affects: All versions
gotchaLimited Maintenance. The `python-magic-bin-extension` GitHub repository shows limited recent activity compared to its upstream `python-magic`. While functional, new features or rapid bug fixes are less likely, and it may not keep up with the latest `libmagic` features or bug fixes.
fix
Be aware that new issues or detection problems might not be resolved quickly. Consider contributing to the project or evaluating the more actively maintained `python-magic` if system-level `libmagic` installation is not an issue for your environment.
affects: All versions
gotchaPotential for Outdated Bundled `libmagic`. Since `libmagic` is bundled within `python-magic-bin`, updates to the underlying `libmagic` library are tied to `python-magic-bin` releases. This means the bundled version might lag behind the latest `libmagic` versions, potentially missing improved detections or security fixes.
fix
Check the `python-magic-bin` release notes for information on the bundled `libmagic` version. If you require the absolute latest `libmagic` features or security patches, consider using `python-magic` and installing the latest `libmagic` via your system package manager.
affects: All versions
Upgrade
Version history
0.4.14latest on PyPI · released Oct 2, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
Resources
python-magic-bin — pip install python-magic-bin · libregistry