Registry / ai-ml / magika

magika

JSON →
library1.0.3pypypi✓ verified 24d ago

Magika is an AI-powered file type detection tool developed by Google. It leverages deep learning to accurately identify content types, supporting over 200 formats including binary and textual files. It boasts high accuracy (~99%) and fast inference times, making it suitable for security, data processing, and development workflows. The current version is 1.0.2, and it receives active development and regular updates.

pip install magika
INSTALL
IMPORT
SIG · MAGIKA
M
magika
ai-mlpythonv1.0.3
Install
7.4s avg
Import
426ms
Disk
177MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.3 · 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.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.4s · import 0.426s · 206MB
177MB installed
● package 177MB
Code
Verified usage

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

Magika
from magika import Magika
PredictionMode
from magika import Magika, PredictionMode
Used for custom instantiation of the Magika class to control prediction confidence.

Instantiate the `Magika` class and use `identify_bytes` or `identify_path` to determine the content type of a file or byte string. The `output.label` field provides the identified content type. For optimal performance with large files, `identify_path` or `identify_stream` are recommended as they avoid loading the entire content into memory.

from magika import Magika import os m = Magika() # Example 1: Identify from bytes file_content_bytes = b"console.log('Hello, Magika!');" result_bytes = m.identify_bytes(file_content_bytes) print(f"Content type (bytes): {result_bytes.output.label}") # Example 2: Identify from a dummy file path # Create a dummy file for demonstration dummy_file_path = "./dummy_script.js" with open(dummy_file_path, "wb") as f: f.write(file_content_bytes) result_path = m.identify_path(dummy_file_path) print(f"Content type (path): {result_path.output.label}") os.remove(dummy_file_path)
magika --version
Debug
Known issues
breakingStarting with version 1.0.2, Magika no longer automatically loads `.env` files. If your application relied on `python-dotenv` being implicitly managed by Magika, this behavior has changed.
fix
Manually load `.env` files using `python-dotenv` if needed, before initializing Magika, or explicitly pass configuration to Magika if such options become available.
affects: >=1.0.2
breakingMagika 1.0 represents a significant rewrite, with the core engine and CLI implemented in Rust, and the Python module being 'revamped.' While intended for easier integration, users migrating from pre-1.0 experimental versions (0.x.x) might encounter API changes or behavioral differences requiring code updates. The Python CLI itself also shifted from a pure Python implementation to a Rust binary wrapper around version 0.6.0.
fix
Consult the official documentation and changelogs for specific migration paths and updated API usage when upgrading from 0.x versions. Review `Magika` class constructor arguments and identification methods.
affects: >=1.0.0 (from <1.0.0)
gotchaFor large files, using `magika.identify_bytes()` can lead to high memory consumption as it loads the entire file content into memory. This is not efficient for very large files.
fix
Prefer `magika.identify_path(path)` or `magika.identify_stream(file_stream)` for large files, as these methods are optimized to read only necessary portions of the file by seeking, reducing memory footprint.
affects: All versions
gotchaThe `onnxruntime` dependency, while crucial for Magika's performance, can be substantial in size and may introduce platform-specific installation complexities. While Magika 1.0.2 improved support for Python 3.14 and removed some Windows-specific pins, `onnxruntime` itself has had historical issues with specific Python versions or architectures.
fix
Ensure you have a compatible `onnxruntime` version for your Python environment and operating system. In case of installation issues, check `onnxruntime`'s official documentation for troubleshooting.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'magika'
The `magika` Python package has not been installed in the active Python environment.
fix
Run `pip install magika` in your terminal to install the library.
ImportError: DLL load failed while importing onnxruntime_pybind11_state
`onnxruntime`, a core dependency of `magika`, requires specific DLLs (e.g., Microsoft Visual C++ Redistributables) that are either missing, outdated, or not properly located in the system's PATH environment variable, a common issue on Windows systems.
fix
Ensure the latest Microsoft Visual C++ Redistributable is installed. Consider upgrading `onnxruntime` (`pip install --upgrade onnxruntime`) or verifying that the necessary DLL directories are correctly added to your system's PATH.
DeprecationWarning: multiprocessing.set_start_method() is deprecated
An underlying dependency of `magika` (likely `onnxruntime`) uses `multiprocessing.set_start_method()`, which is a deprecated function in newer Python versions. Recent `magika` updates may have enabled stricter visibility for deprecation warnings, making this warning appear.
fix
This is a warning and typically does not halt program execution. It can often be safely ignored. If desired, you can suppress it by adding `import warnings; warnings.filterwarnings('ignore', category=DeprecationWarning)` to your code. Library maintainers may address internal handling in future versions.
Circular import: logger ↔ magika
This describes a known internal architectural issue within the `magika` library where `magika/logger.py` and the main `magika` module have a circular dependency. While an internal issue, it can sometimes lead to unexpected import errors depending on the specific Python execution flow.
fix
This is an internal library concern and generally requires a fix from the `magika` maintainers. Users typically cannot resolve this directly, but reporting the specific `ImportError` traceback if encountered can help developers prioritize a fix.
Upgrade
Version history
1.0.3latest on PyPI · released May 4, 2026
Audit
Dependencies
onnxruntimerequiredRequired for running the deep learning model inference.
clickrequiredUsed for command-line interface utilities; part of the Python package distribution.
Agent activity
5 hits · last 30 days
node
4
Resources
magika — pip install magika · libregistry