Registry / serialization / pylibmagic

pylibmagic

JSON →
library0.5.0pypypiunverified

pylibmagic is a lightweight Python package designed to simplify the installation and usage of the `libmagic` C library. It provides pre-compiled `libmagic` shared libraries via Python wheels, primarily addressing the common `ImportError: failed to find libmagic` encountered when using other `libmagic` bindings like `python-magic`. The current version is 0.5.0, with releases focusing on expanding Python version and architecture support.

pip install pylibmagic
INSTALL
IMPORT
SIG · PYLIBMAGIC
P
pylibmagic
serializationpythonv0.5.0
Install
1.6s avg
Import
66ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
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
installs and imports cleanly · install 0.0s · import 0.063s · 25.5MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.069s · 26MB
23MB installed
● package 23MB
Code
Verified usage

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

magic
from pylibmagic import magic
from pylibmagic import magic

This quickstart demonstrates how to use `pylibmagic` in conjunction with the `python-magic` library. `pylibmagic` ensures that the `libmagic` C library is available for `python-magic` to use, solving common installation issues. After importing `pylibmagic`, you can then proceed to use the `magic` module from `python-magic` as intended.

import pylibmagic import magic # pylibmagic ensures the underlying libmagic library is available # You can inspect the data path it uses: print(f"pylibmagic data path: {pylibmagic.data}") # Now, use the python-magic library as usual try: m = magic.Magic() file_type = m.from_buffer(b"hello world") print(f"'hello world' is detected as: {file_type}") # Example with a common file type with open("temp_text.txt", "w") as f: f.write("This is a test file.") file_type_from_file = m.from_file("temp_text.txt") print(f"'temp_text.txt' is detected as: {file_type_from_file}") import os os.remove("temp_text.txt") except Exception as e: print(f"An error occurred: {e}") print("Ensure 'python-magic' is also installed (`pip install python-magic`).")
Debug
Known issues
gotchapylibmagic does not provide the 'magic' module directly. Its purpose is to bundle and make the underlying `libmagic` C library accessible. To use the Python bindings for `libmagic`, you typically need to install `python-magic` separately.
fix
Ensure both `pylibmagic` and `python-magic` are installed: `pip install pylibmagic python-magic`.
affects: All versions
gotchaOn platforms or architectures without pre-built wheels, `pylibmagic` installation might fail or require system-level `libmagic` installation.
fix
On Debian/Ubuntu, install `libmagic1` or `libmagic-dev` (`sudo apt-get install libmagic1`). On macOS, install via Homebrew (`brew install libmagic`). For Windows, `python-magic-bin` might be a more robust solution, or ensure `libmagic` DLLs are correctly placed and match your Python's bitness.
affects: All versions
gotchaUsing a 32-bit `libmagic` DLL with a 64-bit Python (or vice-versa) on Windows can lead to `WindowsError: [Error 193]`.
fix
Ensure that the `libmagic` DLLs and your Python installation are both either 32-bit or 64-bit. Consider using `pip install python-magic-bin` which often includes the correct binaries for Windows.
affects: All versions on Windows
Upgrade
Version history
0.5.0latest on PyPI · released Oct 19, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
22
Resources
pylibmagic — pip install pylibmagic · libregistry