Magika — Google AI File Type Detection Tool
Google's deep learning file type detector with 99%+ accuracy. Magika identifies 200+ file types using AI instead of magic bytes, ideal for security scanning and content processing.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install 82c22f07-4787-47d7-9643-8f3a5ec40706 --target codexRun after dry-run confirms the install plan.
What it is
Magika is a file type detection tool developed by Google that uses deep learning to identify over 200 file types with 99%+ accuracy. Unlike traditional tools that rely on magic bytes or file extensions, Magika analyzes file content using a trained model to make accurate determinations.
It serves security engineers who need reliable file classification for malware scanning, content processing pipelines that handle heterogeneous uploads, and developers building systems where file type matters for routing and validation.
How it saves time or tokens
Magika replaces fragile extension-based checks and unreliable magic-byte heuristics with a single inference call. This eliminates the need for cascading fallback logic when traditional detection fails. The model runs locally without API calls, keeping latency low and avoiding per-request costs. With an estimated 3,200 tokens for the workflow configuration, integration is straightforward.
How to use
- Install Magika via pip or use the pre-built CLI binary.
- Point it at a file or directory to get file type predictions with confidence scores.
- Integrate the Python API into your pipeline for programmatic file routing.
Example
# Install and run Magika CLI
pip install magika
magika /path/to/unknown_file
# Output: /path/to/unknown_file: Python source (python)
# Batch scan a directory
magika /uploads/*
from magika import Magika
m = Magika()
result = m.identify_path('/path/to/file')
print(result.output.ct_label) # e.g., 'python'
print(result.output.score) # e.g., 0.999
Related on TokRepo
- AI Tools for Security — Security-focused AI tools for scanning and analysis
- AI Tools for Automation — Automate file processing and content pipelines
Common pitfalls
- Assuming Magika replaces antivirus scanning. It identifies file types, not malicious content.
- Using file extensions as a fallback when Magika returns low confidence. Instead, treat low-confidence results as genuinely ambiguous files.
- Running Magika on extremely large files without understanding that it only reads a small prefix for classification.
Frequently Asked Questions
Magika achieves 99%+ accuracy across its supported file types, significantly outperforming the traditional Unix file command on polyglot files, obfuscated content, and edge cases where magic bytes are ambiguous or misleading.
No. Magika uses a lightweight model that runs efficiently on CPU. Inference takes milliseconds per file, making it suitable for batch processing on standard hardware without GPU acceleration.
Magika detects file types, not malware. It can identify when a file claiming to be a PDF is actually a Windows executable, which is useful for security screening, but it does not perform malware signature matching or behavioral analysis.
Magika supports over 200 file types including programming languages, document formats, image formats, archives, executables, and media files. The full list is available in the project repository.
Yes. Magika is open source under the Apache 2.0 license, published by Google on GitHub. The model weights and training pipeline are included in the repository.
Citations (3)
- Magika GitHub— 99%+ accuracy across 200+ file types
- Google Security Blog— Deep learning approach to file type detection
- Magika README— Apache 2.0 open source license
Related on TokRepo
Source & Thanks
Created by Google. Licensed under Apache 2.0.
google/magika — 8k+ stars
Discussion
Related Assets
nnn — n³ The Fastest Terminal File Manager Ever Written
nnn is a full-featured, ultra-fast, zero-config terminal file manager written in C, with a plugin ecosystem, type-to-nav, mounting, disk usage analysis, and batch renaming.
Guava — Google Core Libraries for Java
Google's suite of core Java libraries covering collections, caching, primitives, concurrency, common annotations, string processing, I/O, and more.
Yazi — Blazing Fast Terminal File Manager in Rust
Yazi is a blazing fast terminal file manager written in Rust, based on async I/O. Preview images and videos in terminal, fuzzy search, batch operations, plugin system, and seamless integration with tools like fzf, zoxide, and rg.
Lighthouse — Automated Web Performance Auditing by Google
An open-source tool by Google that audits web pages for performance, accessibility, SEO, and best practices, available in Chrome DevTools, as a CLI, and as a Node module.