Fast and accurate AI powered file content types detection
Fast and accurate AI powered file content types detection
Magika is a novel AI-powered file type detection tool that relies on the recent advance of deep learning to provide accurate detection. Under the hood, Magika employs a custom, highly optimized model that only weighs about a few MBs, and enables precise file identification within milliseconds, even when running on a single CPU. Magika has been trained and evaluated on a dataset of ~100M samples across 200+ content types (covering both binary and textual file formats), and it achieves an average ~99% accuracy on our test set.
Here is an example of what Magika command line output looks like:
Magika is used at scale to help improve Google users' safety by routing Gmail, Drive, and Safe Browsing files to the proper security and content policy scanners, processing hundreds billions samples on a weekly basis. Magika has also been integrated with VirusTotal (example) and abuse.ch (example).
For more context you can read our initial announcement post on Google's OSS blog, you can consult Magika's website, and you can read more in our research paper, published at the IEEE/ACM International Conference on Software Engineering (ICSE) 2025.
You can try Magika without installing anything by using our web demo, which runs locally in your browser!
-r for recursively scanning a directory.high-confidence, medium-confidence, and best-guess.Magika ships a CLI written in Rust, and can be installed in several ways.
Via magika python package:
pipx install magikaVia brew (macOS / Linux)
brew install magikaVia installer script:
curl -LsSf https://securityresearch.google/magika/install.sh | shor:
powershell -ExecutionPolicy Bypass -c "irm https://securityresearch.google/magika/install.ps1 | iex"Via magika-cli Rust package:
cargo install --locked magika-clipip install magikanpm install magikaHere you can find a number of quick examples just to get you started.
To learn about Magika's inner workings, see the Core Concepts section of Magika's website.
% cd tests_data/basic && magika -r * | head
asm/code.asm: Assembly (code)
batch/simple.bat: DOS batch file (code)
c/code.c: C source (code)
css/code.css: CSS source (code)
csv/magika_test.csv: CSV document (code)
dockerfile/Dockerfile: Dockerfile (code)
docx/doc.docx: Microsoft Word 2007+ document (document)
docx/magika_test.docx: Microsoft Word 2007+ document (document)
eml/sample.eml: RFC 822 mail (text)
empty/empty_file: Empty file (inode)…% cat tests_data/basic/ini/doc.ini | magika -
-: INI configuration file (text)…For more examples and documentation about the CLI, see https://crates.io/crates/magika-cli.
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_bytes(b'function log(msg) {console.log(msg);}')
>>> print(res.output.label)
javascript>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_path('./tests_data/basic/ini/doc.ini')
>>> print(res.output.label)
ini>>> from magika import Magika
>>> m = Magika()
>>> with open('./tests_data/basic/ini/doc.ini', 'rb') as f:
>>> res = m.identify_stream(f)
>>> print(res.output.label)
iniFor more examples and documentation about the Python module, see the Python Magika module section.
Please consult Magika's website for detailed documentation about:
Please contact us directly at [email protected].
Apache 2.0; see LICENSE for details.
This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.
kb: food for thought on cross-checking rust/gen/content_types and YARA rule coverage
starting from the yaml content type KB + json with rules/ML coverage, auto-generate HTML table for the docs
once the new KB management system is in, update CONTRIBUTING.md
[python] Consider publishing a source distribution (sdist) for the PyO3-based Python package
Tract CPU runtime: one file prepares three plans at startup (~5 ms instead of ~2 ms on arm64)
CLI start pays about 1.5 ms for linking Metal even when it never uses the GPU
[magika-lib] Handle non-regular / special files (/dev/null, FIFOs, devices, sockets) as ContentType::Unknown
[magika-lib] Support no_dereference option in Session::identify_file and FeaturesOrRuled::extract_file
[magika-lib] Expose static content-type metadata and model/output label spaces to eliminate Python JSON configs
[magika-lib] Support PredictionMode (HighConfidence, MediumConfidence, BestGuess)