Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

magika

> 编程语言
Open source

Fast and accurate AI powered file content types detection

17.9K stars0 likes2 views
WebsiteGitHub

About

Fast and accurate AI powered file content types detection

Magika

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
    2. Quick Start
  2. Documentation
  3. Security Vulnerabilities
  4. License
  5. 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:

bash
pipx install magika

Via brew (macOS / Linux)

bash
brew install magika

Via installer script:

bash
curl -LsSf https://securityresearch.google/magika/install.sh | sh

or:

bash
powershell -ExecutionPolicy Bypass -c "irm https://securityresearch.google/magika/install.ps1 | iex"

Via magika-cli Rust package:

bash
cargo install --locked magika-cli

Python package

bash
pip install magika

JavaScript package

bash
npm install magika

Quick Start

Here 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.

Command Line Tool Examples

bash
% 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)
…
bash
% 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.

Python Examples

python
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_bytes(b'function log(msg) {console.log(msg);}')
>>> print(res.output.label)
javascript
python
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_path('./tests_data/basic/ini/doc.ini')
>>> print(res.output.label)
ini
python
>>> 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)
ini

For more examples and documentation about the Python module, see the Python Magika module section.

Documentation

Please consult Magika's website for detailed documentation about:

  • Core Concepts
    • How Magika works
    • Models & content types
    • Prediction modes
    • Understanding the output
  • CLI & Bindings (Python module, JavaScript module, ...)
  • Contributing
  • FAQ
  • ...

Security Vulnerabilities

Please contact us directly at [email protected].

License

Apache 2.0; see LICENSE for details.

Disclaimer

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.

Issues· 176 open

View all issuesOpen on GitHub
  • #1521

    kb: food for thought on cross-checking rust/gen/content_types and YARA rule coverage

    Updated Oct 1, 2026
  • #1514

    starting from the yaml content type KB + json with rules/ML coverage, auto-generate HTML table for the docs

    Updated Oct 1, 2026
  • #1513

    once the new KB management system is in, update CONTRIBUTING.md

    Updated Oct 1, 2026
  • #1499

    [python] Consider publishing a source distribution (sdist) for the PyO3-based Python package

    Updated Sep 25, 2026
  • #1497

    Tract CPU runtime: one file prepares three plans at startup (~5 ms instead of ~2 ms on arm64)

    Updated Sep 25, 2026
  • #1493

    CLI start pays about 1.5 ms for linking Metal even when it never uses the GPU

    Updated Sep 25, 2026
  • #1482

    [magika-lib] Handle non-regular / special files (/dev/null, FIFOs, devices, sockets) as ContentType::Unknown

    Updated Sep 18, 2026
  • #1481

    [magika-lib] Support no_dereference option in Session::identify_file and FeaturesOrRuled::extract_file

    Updated Sep 18, 2026
  • #1480

    [magika-lib] Expose static content-type metadata and model/output label spaces to eliminate Python JSON configs

    Updated Sep 18, 2026
  • #1479

    [magika-lib] Support PredictionMode (HighConfidence, MediumConfidence, BestGuess)

    Updated Sep 18, 2026

> Tags

Pythonaideep-learningfiletypekeras-classification-models

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言