google/magika

Fast and accurate AI powered file content types detection

What it solves

Magika is an AI-powered file type detection tool that accurately identifies the content type of files, including both binary and textual formats. It solves the problem of misdetection, especially for text files, where traditional signature-based tools often fail. It's fast and lightweight enough to run on a single CPU.

How it works

Magika uses a custom deep learning model that weighs only a few MBs. It reads a limited subset of each file's content, so inference time stays near-constant regardless of file size. After a one-off model load, it identifies a file in about 5ms on a single CPU. The model was trained on ~100M samples across 200+ content types and achieves ~99% average precision and recall. Magika uses a per-content-type threshold system to decide whether to trust a prediction or fall back to a generic label like "Generic text document". Prediction modes (high-confidence, medium-confidence, best-guess) let you control tolerance to errors.

Who it's for

Magika is for developers, security researchers, and organizations that need fast, accurate file type identification at scale. It's already used by Google to route files in Gmail, Drive, and Safe Browsing to the right scanners, and it's integrated with VirusTotal and abuse.ch. You can use it as a command-line tool, a Python API, or via bindings for Rust, JavaScript/TypeScript, and Go (work in progress).

Highlights

  • Available as a Rust CLI, Python API, and bindings for Rust, JavaScript/TypeScript, and Go (WIP).
  • Trained on ~100M files across 200+ content types.
  • ~99% average precision and recall on the test set, outperforming existing approaches, especially on textual content.
  • ~5ms inference per file after model load, even on a single CPU.
  • Can process thousands of files at once; supports recursive directory scanning with -r.
  • Near-constant inference time independent of file size, using only a limited subset of content.
  • Per-content-type threshold system to decide when to trust predictions vs. return generic labels.
  • Prediction modes: high-confidence, medium-confidence, best-guess.
  • Open source under Apache 2.0.

Related

  • Project
  • Project
  • Project
  • Project
  • Dispatch