google /magika
Fast and accurate AI powered file content types detection
★ 18,798⑂ 1,188👁 70⑃ 946● 675▤ 15
-1
日增长
+38
周增长
+77
月增长
18,798
stars
1,188
forks
70
watchers
946
prs
675
issues
15
releases
README
Magika
!CodeQL
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!
Highlights
- Available as a command line tool written in Rust, a Python API, and additional bindings for Rust, JavaScript/TypeScript (with an experimental npm package, which powers our web demo), and GoLang (WIP).
- Trained and evaluated on a dataset of ~100M files across 200+ content types.
- On our test set, Magika achieves ~99% average precision and recall, outperforming existing approaches -- especially on textual content types.
- After the model is loaded (which is a one-off overhead), the inference time is about 5ms per file, even when run on a single CPU.
- You can invoke Magika with even thousands of files at the same time. You can also use -r for recursively scanning a directory.
- Near-constant inference time, independently from the file size; Magika only uses a limited subset of the file's content.
- Magika uses a per-content-type threshold system that determines whether to "trust" the prediction for the model, or whether to return a generic label, such as "Generic text document" or "Unknown binary data".
- The tolerance to errors can be controlled via different prediction modes, such as high-confidence, medium-confidence, and best-guess.
- The client and the bindings are already open source, and more is coming soon!
Table of Contents
1. Getting Started
1. Installation
1. Quick Start
1. Documentation
1. Security Vulnerabilities
1. License
1. Disclaimer
Getting Started
Installation
Command Line Tool
Magika ships a CLI written in Rust, and can be installed in several ways.
Via magika python package:
shell
pipx install magika
Via brew (macOS / Linux)
shell
brew install magika
Via installer script:
shell
curl -LsSf https://securityresearch.google/mTop issues
#679Convert python API into a dynamic-link library for Linux15 comments · 2024-09-10#152Define a more managable workflow to keep track of requested new content types11 comments · 2024-02-20#662Add more "basic" tests samples to cover supported content types10 comments · 2024-08-30#593Keep support for model v1 within the rust client9 comments · 2024-07-24#1323Removing ort/ndarray compatibility pin also breaks Linux arm64 builds8 comments · 2026-03-18#1261Training from scratch7 comments · 2026-01-04#1243Light gray on white is no good7 comments · 2025-11-13#276emebed model.json and config.json7 comments · 2024-03-02
Latest release
cli/v1.1.0 cli/v1.1.0 2026-04-24Install magika-cli 1.1.0 Install prebuilt binaries via shell script sh curl --proto '=https' --tlsv1.2 -LsSf https://github.com/google/magika/releases/download/cli/v1.1.0/magika-cli-installer.sh | sh Install prebuilt binaries via powershell script sh powershell -ExecutionPolicy Bypass -c "irm https://github.com/google/magika/releases/download/cli/v1.1.0/magika-cli-installer.ps1 | iex" Download magika-cli 1.1.0 | File | Platform | Checksum | |--------|----------|----------| | magika-cli-aarch64-apple-darwin.tar.xz | Apple Silicon macOS | checksum | | magika-cli-x86_64-pc-windows-ms