Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.2%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Detect file content types with deep learning
Basic Info
- Host: GitHub
- Owner: google
- License: apache-2.0
- Language: Python
- Default Branch: main
- Homepage: https://google.github.io/magika/
- Size: 81.4 MB
Statistics
- Stars: 8,751
- Watchers: 39
- Forks: 452
- Open Issues: 110
- Releases: 6
Topics
Metadata Files
README.md
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, 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! (Note: the website runs an older version of the model; but while results may differ, it is still useful to get an idea of Magika's capabilities.)
[!IMPORTANT]
- The documentation on GitHub refers to the latest, potentially unreleased and unstable version of Magika. The latest stable release of the
magikaPython package is0.6.1, and you can consult the associated documentation here. You can install the latest stable version with:pip install magika.- A detailed changelog and migration guidelines from older versions are discussed here.
- Help testing the latest release candidate is very appreciated! See the available candidates here and the recent changes in the CHANGELOG.md. You can install the latest release candidate with
pip install --pre magika.
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.
- 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
-rfor 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, andbest-guess. - The client and the bindings are already open source, and more is coming soon!
Table of Contents
- Getting Started
- Documentation
- Bindings
- Development Setup
- Known Limitations & Contributing
- Additional Resources
- Research Paper and Citation
- Security vulnerabilities
- License
- Disclaimer
Getting Started
Installation
Magika is available as magika on PyPI:
shell
$ pip install magika
If you intend to use Magika only as a command line, you may want to use $ pipx install magika instead.
If you want to test out the latest release candidate, you can install with pip install --pre magika.
If you want to test Magika within a Docker container, you can run:
shell
git clone https://github.com/google/magika
cd magika/
docker build -t magika .
docker run -it --rm -v $(pwd):/magika magika -r /magika/tests_data/basic
Usage
Command line client
Magika is available as a command line tool, written in Rust (the magika python package ships this client). Here below are a few examples on how to use it, and the output of magika --help, which documents the list of options. See here for developer notes and documentation on how to install the Rust client via cargo.
Examples:
shell
$ cd tests_data/basic && magika -r *
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)
epub/doc.epub: EPUB document (document)
epub/magika_test.epub: EPUB document (document)
flac/test.flac: FLAC audio bitstream data (audio)
handlebars/example.handlebars: Handlebars source (code)
html/doc.html: HTML document (code)
ini/doc.ini: INI configuration file (text)
javascript/code.js: JavaScript source (code)
jinja/example.j2: Jinja template (code)
jpeg/magika_test.jpg: JPEG image data (image)
json/doc.json: JSON document (code)
latex/sample.tex: LaTeX document (text)
makefile/simple.Makefile: Makefile source (code)
markdown/README.md: Markdown document (text)
[...]
shell
$ magika ./tests_data/basic/python/code.py --json
[
{
"path": "./tests_data/basic/python/code.py",
"result": {
"status": "ok",
"value": {
"dl": {
"description": "Python source",
"extensions": [
"py",
"pyi"
],
"group": "code",
"is_text": true,
"label": "python",
"mime_type": "text/x-python"
},
"output": {
"description": "Python source",
"extensions": [
"py",
"pyi"
],
"group": "code",
"is_text": true,
"label": "python",
"mime_type": "text/x-python"
},
"score": 0.753000020980835
}
}
}
]
shell
$ cat doc.ini | magika -
-: INI configuration file (text)
```help $ magika --help Determines the content type of files with deep-learning
Usage: magika [OPTIONS] [PATH]...
Arguments: [PATH]... List of paths to the files to analyze.
Use a dash (-) to read from standard input (can only be used once).
Options: -r, --recursive Identifies files within directories instead of identifying the directory itself
--no-dereference
Identifies symbolic links as is instead of identifying their content by following them
--colors
Prints with colors regardless of terminal support
--no-colors
Prints without colors regardless of terminal support
-s, --output-score Prints the prediction score in addition to the content type
-i, --mime-type Prints the MIME type instead of the content type description
-l, --label Prints a simple label instead of the content type description
--json
Prints in JSON format
--jsonl
Prints in JSONL format
--format <CUSTOM>
Prints using a custom format (use --help for details).
The following placeholders are supported:
%p The file path
%l The unique label identifying the content type
%d The description of the content type
%g The group of the content type
%m The MIME type of the content type
%e Possible file extensions for the content type
%s The score of the content type for the file
%S The score of the content type for the file in percent
%b The model output if overruled (empty otherwise)
%% A literal %
-h, --help Print help (see a summary with '-h')
-V, --version Print version ```
Python module and other bindings
While the command line client is handy for many use cases, it may not be the most suitable for automated workflows. Thus, Magika comes with bindings for Python and other languages (see the Bindings section below for more details).
Here is a few examples on how to use the Magika Python module:
```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.identifypath('./testsdata/basic/ini/doc.ini') print(res.output.label) ini ```
```python
from magika import Magika m = Magika() with open('./testsdata/basic/ini/doc.ini', 'rb') as f: res = m.identifystream(f) print(res.output.label) ini ```
Please consult the python documentation for details on the Python Magika API, and the additional documentation listed below for more information about the output format and other aspects.
Documentation
- Core concepts: models, prediction mode, magika's output, and content types knowledge base
- List of supported content types by the latest model,
standard_v3_3 - Documentation about the CLI
- Documentation about the python
magikapackage and module - Frequently Asked Questions
Bindings
| Artifact | Status | Latest version | Default model |
| -------------------------------------------------------------------------- | -------------- | -------------- | ---------------------------------------------------------- |
| Python Magika module | Stable | 0.6.2 | standard_v3_3 |
| Rust magika CLI | Stable | 0.1.2 | standard_v3_3 |
| Rust magika library | Stable | 0.2.0 | standard_v3_3 |
| TypeScript / NPM package (README & docs) | Stable | 0.3.2 | standard_v3_3 |
| Demo Website | Stable | - | standard_v3_3 |
| GoLang | In development | - | - |
Development Setup
We have Magika bindings in multiple languages; each of them has its own development setup. Consult the documentation associated to each binding for more information. For example, for the python magika package and module, consult python/README.md.
Known Limitations & Contributing
Magika significantly improves over the state of the art, but there's always room for improvement! More work can be done to increase detection accuracy, support for additional content types, bindings for more languages, etc.
This initial release is not targeting polyglot detection, and we're looking forward to seeing adversarial examples from the community. We would also love to hear from the community about encountered problems, misdetections, features requests, need for support for additional content types, etc.
Check our open GitHub issues to see what is on our roadmap and please report misdetections or feature requests by either opening GitHub issues (preferred) or by emailing us at magika-dev@google.com.
NOTE: Do NOT send reports about files that may contain PII!
See CONTRIBUTING.md for details.
Additional Resources
- Google's OSS blog post about Magika announcement.
- Web demo: web demo.
Research Paper and Citation
We describe how we developed Magika and the choices we made in our research paper, which was accepted at the International Conference on Software Engineering (ICSE) 2025. You can find a copy of the paper here. (A previous version of our paper is available on arxiv: https://arxiv.org/abs/2409.13768.)
If you use this software for your research, please cite it as:
bibtex
@InProceedings{fratantonio25:magika,
author = {Yanick Fratantonio and Luca Invernizzi and Loua Farah and Kurt Thomas and Marina Zhang and Ange Albertini and Francois Galilee and Giancarlo Metitieri and Julien Cretin and Alexandre Petit-Bianco and David Tao and Elie Bursztein},
title = {{Magika: AI-Powered Content-Type Detection}},
booktitle = {Proceedings of the International Conference on Software Engineering (ICSE)},
month = {April},
year = {2025}
}
Security vulnerabilities
Please contact us directly at magika-dev@google.com
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.
Owner
- Name: Google
- Login: google
- Kind: organization
- Email: opensource@google.com
- Location: United States of America
- Website: https://opensource.google/
- Twitter: GoogleOSS
- Repositories: 2,773
- Profile: https://github.com/google
Google ❤️ Open Source
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." authors: - family-names: "Fratantonio" given-names: "Yanick" - family-names: "Invernizzi" given-names: "Luca" - family-names: "Farah" given-names: "Loua" - family-names: "Kurt" given-names: "Thomas" - family-names: "Zhang" given-names: "Marina" - family-names: "Albertini" given-names: "Ange" - family-names: "Galilee" given-names: "Francois" - family-names: "Metitieri" given-names: "Giancarlo" - family-names: "Cretin" given-names: "Julien" - family-names: "Petit-Bianco" given-names: "Alexandre" - family-names: "Tao" given-names: "David" - family-names: "Bursztein" given-names: "Elie" title: "Magika: AI-Powered Content-Type Detection" url: "https://arxiv.org/abs/2409.13768"
GitHub Events
Total
- Create event: 189
- Release event: 5
- Issues event: 205
- Watch event: 964
- Delete event: 171
- Issue comment event: 285
- Push event: 453
- Pull request review comment event: 54
- Pull request event: 410
- Pull request review event: 140
- Fork event: 50
Last Year
- Create event: 189
- Release event: 5
- Issues event: 205
- Watch event: 964
- Delete event: 171
- Issue comment event: 285
- Push event: 453
- Pull request review comment event: 54
- Pull request event: 410
- Pull request review event: 140
- Fork event: 50
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Yanick Fratantonio | y****f@g****m | 693 |
| Luca Invernizzi | i****l@g****m | 199 |
| dependabot[bot] | 4****] | 97 |
| Julien Cretin | c****n@g****m | 61 |
| Juan Calderon-Perez | j****z@p****m | 20 |
| NintenHero | 3****s | 14 |
| anzerr | t****r@g****m | 14 |
| Mohit Gaur | 5****r | 7 |
| TheMythologist | l****1@g****m | 6 |
| Bregwin Jogi | b****l@g****m | 5 |
| 0xb-s | 1****s | 4 |
| Ange Albertini | 1****g | 4 |
| ps2181 | h****1@g****m | 4 |
| jogo- | j****o@l****t | 3 |
| Elie Bursztein | g****b@e****t | 3 |
| ChinoUkaegbu | 7****u | 3 |
| hauntsaninja | h****a@g****m | 2 |
| Thomas Roccia | t****a@g****m | 2 |
| Parth P Shah | p****9@g****m | 2 |
| Parth P Shah | 3****h | 2 |
| Christophe Faribault | c****t@g****m | 2 |
| ADARSH KUMAR SINGH | 7****9 | 2 |
| Maxim Tugunchinov | t****m@g****m | 1 |
| Lawrence Moorehead | l****d@e****m | 1 |
| Francois Galilee | g****e@g****m | 1 |
| Giancarlo Metitieri | g****i@g****m | 1 |
| Oona Räisänen | o****a@k****i | 1 |
| abhin2002 | a****0@g****m | 1 |
| Bartosz Sławecki | b****v@g****m | 1 |
| Filipe Regadas | o****s@r****l | 1 |
| and 7 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 288
- Total pull requests: 401
- Average time to close issues: 27 days
- Average time to close pull requests: 15 days
- Total issue authors: 69
- Total pull request authors: 23
- Average comments per issue: 0.94
- Average comments per pull request: 0.55
- Merged pull requests: 213
- Bot issues: 1
- Bot pull requests: 201
Past Year
- Issues: 112
- Pull requests: 236
- Average time to close issues: 26 days
- Average time to close pull requests: 13 days
- Issue authors: 26
- Pull request authors: 8
- Average comments per issue: 0.81
- Average comments per pull request: 0.31
- Merged pull requests: 140
- Bot issues: 1
- Bot pull requests: 99
Top Authors
Issue Authors
- MichaelHinrichs (267)
- reyammer (121)
- ebursztein (5)
- gelim (4)
- xiangchen96 (4)
- luckyservant (3)
- dependabot[bot] (2)
- Nicba1010 (2)
- andrewcrook (2)
- amone-bit (2)
- invernizzi (2)
- dbohdan (2)
- riklaunim (2)
- Maijin (2)
- asafbana (2)
Pull Request Authors
- dependabot[bot] (369)
- reyammer (187)
- ia0 (62)
- invernizzi (22)
- ps2181 (9)
- TheMythologist (8)
- abhin2002 (8)
- MichaelHinrichs (6)
- eltociear (4)
- UberGuidoZ (4)
- jogo- (4)
- devilkadabra69 (3)
- gaby (3)
- 0xb-s (3)
- nhonx (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 6
-
Total downloads:
- pypi 988,656 last-month
- cargo 28,805 total
- npm 2,196 last-month
-
Total dependent packages: 7
(may contain duplicates) -
Total dependent repositories: 0
(may contain duplicates) - Total versions: 52
- Total maintainers: 6
proxy.golang.org: github.com/google/magika
- Documentation: https://pkg.go.dev/github.com/google/magika#section-documentation
- License: apache-2.0
-
Latest release: v0.5.0
published about 2 years ago
Rankings
crates.io: magika
Determines the content type of a file with deep-learning
- Homepage: https://google.github.io/magika/
- Documentation: https://docs.rs/magika/
- License: Apache-2.0
-
Latest release: 0.2.1
published 9 months ago
Rankings
Maintainers (3)
pypi.org: magika
A tool to determine the content type of a file with deep learning
- Homepage: https://github.com/google/magika
- Documentation: https://github.com/google/magika/blob/main/python/README.md
- License: Apache-2.0
-
Latest release: 0.6.2
published 10 months ago
Rankings
Maintainers (2)
anaconda.org: magika
Magika is a tool to determine the content type of a file with deep-learning. It is designed to be used in a pipeline to determine the content type of a file before it is processed by other tools. It is not designed to be used as a standalone tool, but rather as a component in a larger system.
- Homepage: https://github.com/google/magika
- License: Apache-2.0
-
Latest release: 0.6.1
published 10 months ago
Rankings
crates.io: magika-cli
Determines the content type of a file with deep-learning
- Homepage: https://google.github.io/magika/
- Documentation: https://docs.rs/magika-cli/
- License: Apache-2.0
-
Latest release: 0.1.3
published 9 months ago
Rankings
Maintainers (2)
Dependencies
- actions/checkout v4 composite
- abatilo/actions-poetry v2 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- actions/checkout v4 composite
- actions/setup-node v4 composite
- actions/checkout v4 composite
- actions/configure-pages v3 composite
- actions/deploy-pages v2 composite
- actions/setup-node v4 composite
- actions/upload-pages-artifact v2 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- snok/install-poetry v1 composite
- tschm/token-mint-action v1.0.3 composite
- abatilo/actions-poetry v2 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- documentation ^14.0.3 development
- @tensorflow/tfjs ^4.17.0
- 375 dependencies
- @vitejs/plugin-vue ^4.2.3 development
- eslint ^8.53.0 development
- eslint-config-airbnb-base ^15.0.0 development
- eslint-plugin-import ^2.29.0 development
- eslint-plugin-vue ^9.18.1 development
- magika ^0.2.4 development
- prettier ^3.2.5 development
- sass ^1.60.0 development
- unplugin-fonts ^1.0.3 development
- vite ^5.1.3 development
- vite-plugin-vuetify ^2.0.1 development
- @mdi/font 7.0.96
- highlight.js ^11.9.0
- lodash ^4.17.21
- markdown-it ^14.0.0
- roboto-fontface *
- vue ^3.2.0
- vue-router ^4.0.0
- vuetify ^3.5.3
- 388 dependencies
- absl-py 2.1.0
- astunparse 1.6.3
- cachetools 5.3.2
- certifi 2024.2.2
- charset-normalizer 3.3.2
- chex 0.1.85
- etils 1.6.0
- flatbuffers 23.5.26
- flax 0.8.1
- fsspec 2024.2.0
- gast 0.4.0
- google-auth 2.27.0
- google-auth-oauthlib 1.0.0
- google-pasta 0.2.0
- grpcio 1.60.1
- h5py 3.10.0
- idna 3.6
- importlib-resources 6.1.1
- jax 0.4.24
- jaxlib 0.4.24
- keras 2.15.0
- libclang 16.0.6
- markdown 3.5.2
- markdown-it-py 3.0.0
- markupsafe 2.1.5
- mdurl 0.1.2
- ml-dtypes 0.2.0
- msgpack 1.0.7
- nest-asyncio 1.6.0
- numpy 1.24.3
- oauthlib 3.2.2
- opt-einsum 3.3.0
- optax 0.1.9
- orbax-checkpoint 0.4.4
- packaging 23.2
- pandas 2.2.0
- protobuf 4.25.2
- pyasn1 0.5.1
- pyasn1-modules 0.3.0
- pygments 2.17.2
- python-dateutil 2.8.2
- pytz 2024.1
- pyyaml 6.0.1
- requests 2.31.0
- requests-oauthlib 1.3.1
- rich 13.7.0
- rsa 4.9
- scipy 1.12.0
- setuptools 69.1.0
- six 1.16.0
- tensorboard 2.15.2
- tensorboard-data-server 0.7.2
- tensorflow 2.15.0
- tensorflow-decision-forests 1.8.1
- tensorflow-estimator 2.15.0
- tensorflow-hub 0.16.1
- tensorflow-io-gcs-filesystem 0.36.0
- tensorflowjs 4.17.0
- tensorstore 0.1.45
- termcolor 2.4.0
- tf-keras 2.15.0
- toolz 0.12.1
- typing-extensions 4.5.0
- tzdata 2024.1
- urllib3 2.2.0
- werkzeug 3.0.1
- wheel 0.42.0
- wrapt 1.14.1
- wurlitzer 3.0.3
- zipp 3.17.0
- python >=3.10,<3.12
- tensorflowjs ^4.17.0
- appnope 0.1.3
- asttokens 2.2.1
- backcall 0.2.0
- click 8.1.6
- colorama 0.4.6
- coloredlogs 15.0.1
- decorator 5.1.1
- exceptiongroup 1.1.2
- executing 1.2.0
- flatbuffers 23.5.26
- humanfriendly 10.0
- iniconfig 2.0.0
- ipython 8.12.2
- jedi 0.19.0
- matplotlib-inline 0.1.6
- mpmath 1.3.0
- mypy 1.8.0
- mypy-extensions 1.0.0
- numpy 1.24.4
- onnxruntime 1.15.1
- packaging 23.1
- parso 0.8.3
- pexpect 4.8.0
- pickleshare 0.7.5
- pluggy 1.2.0
- prompt-toolkit 3.0.39
- protobuf 4.23.4
- ptyprocess 0.7.0
- pure-eval 0.2.2
- pygments 2.15.1
- pyreadline3 3.4.1
- pytest 7.4.0
- python-dotenv 1.0.1
- ruff 0.2.1
- six 1.16.0
- stack-data 0.6.2
- sympy 1.12
- tabulate 0.9.0
- tomli 2.0.1
- tqdm 4.65.0
- traitlets 5.9.0
- typing-extensions 4.7.1
- wcwidth 0.2.6
- ipython ^8.10.0 develop
- mypy ^1.8.0 develop
- pytest ^7.4.0 develop
- ruff ^0.2.1 develop
- click ^8.1.3
- numpy ^1.24.4
- onnxruntime ^1.15.1
- python ^3.8,<3.12
- python-dotenv ^1.0.1
- tabulate ^0.9.0
- tqdm ^4.64.1