Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Magika Python Package

image NPM Version image image OpenSSF Best Practices CodeQL Coverage Status Actions status PyPI Monthly Downloads PyPI Downloads

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.

Use Magika as a command line client or in your Python code!

You can find more information on which content types are supported, extended documentation, and bindings for other languages on Magika's website at https://securityresearch.google/magika/.

Installing Magika

Magika is available as magika on PyPI:

To install the most recent stable version:

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 it with pip install --pre magika.

Using Magika as a command-line tool

Beginning with version 0.6.0, the magika Python package includes a pre-compiled Rust-based command-line tool, replacing the previous Python version. This binary is distributed as platform-specific wheels for most common architectures. For unsupported platforms, a pure-Python wheel is also available, providing the legacy Python client as a fallback.

$ 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)
[...]
$ 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
      }
    }
  }
]
$ cat doc.ini | magika -
-: INI configuration file (text)
$ 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

Check the Rust CLI docs for more information.

Using Magika as a Python module

Here are a few examples of how to use the Magika Python module:

>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_bytes(b'function log(msg) {console.log(msg);}')
>>> print(res.output.label)
javascript
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_path('./tests_data/basic/ini/doc.ini')
>>> print(res.output.label)
ini

When classifying multiple files on disk, pass them together to identify_paths() so feature extraction and model inference run in parallel batches inside the native Rust pipeline:

>>> from magika import Magika
>>> m = Magika()
>>> results = m.identify_paths([
...     './tests_data/basic/ini/doc.ini',
...     './tests_data/basic/python/code.py',
... ])
>>> print([r.output.label for r in results])
['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

Core Concepts

To get the most out of Magika, it's worth learning about its core concepts. You can read about how Magika works, the models, the supported content types, the prediction modes, and notes on how to understand all parts of the output in the Core Concepts section of Magika's website.

API documentation

The Python API is documented in the Python bindings section of Magika's website, and via docstrings in the Magika module source code.

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.

If you use this software for your research, please cite it as:

@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}
}

Metadata

Release files for magika 2.0.0rc0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for magika 2.0.0rc0
File Actions
magika-2.0.0rc0-cp38-abi3-win_arm64.whl CPython 3.8 abi3 Windows ARM64 Details for magika-2.0.0rc0-cp38-abi3-win_arm64.whl
magika-2.0.0rc0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for magika-2.0.0rc0-cp38-abi3-win_amd64.whl
magika-2.0.0rc0-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details for magika-2.0.0rc0-cp38-abi3-musllinux_1_2_x86_64.whl
magika-2.0.0rc0-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details for magika-2.0.0rc0-cp38-abi3-musllinux_1_2_aarch64.whl
magika-2.0.0rc0-cp38-abi3-manylinux_2_31_riscv64.whl CPython 3.8 abi3 Linux glibc 2.31+ RISC-V 64 Details for magika-2.0.0rc0-cp38-abi3-manylinux_2_31_riscv64.whl
magika-2.0.0rc0-cp38-abi3-manylinux_2_28_x86_64.whl CPython 3.8 abi3 Linux glibc 2.28+ x86-64 Details for magika-2.0.0rc0-cp38-abi3-manylinux_2_28_x86_64.whl
magika-2.0.0rc0-cp38-abi3-manylinux_2_28_aarch64.whl CPython 3.8 abi3 Linux glibc 2.28+ ARM64 Details for magika-2.0.0rc0-cp38-abi3-manylinux_2_28_aarch64.whl
magika-2.0.0rc0-cp38-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl CPython 3.8 abi3 Linux glibc 2.17+ ARMv7l Details for magika-2.0.0rc0-cp38-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl
magika-2.0.0rc0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details for magika-2.0.0rc0-cp38-abi3-macosx_11_0_arm64.whl
magika-2.0.0rc0-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details for magika-2.0.0rc0-cp38-abi3-macosx_10_12_x86_64.whl

Total release size: 210.7 MB

Release files / magika-2.0.0rc0-cp38-abi3-win_arm64.whl

Download URL magika-2.0.0rc0-cp38-abi3-win_arm64.whl
Size 18.9 MB
Tags CPython 3.8 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
d55005b28f322e21dfc028ffba1e1d680936ebe2464ace0871a5c3b81f82e53c
BLAKE2b-256 checksum
How to use checksums
c6f549d975ffc8c99b909ab2e4cad5b9c72f3b33cd32b3965052414730b8067a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-win_amd64.whl

Download URL magika-2.0.0rc0-cp38-abi3-win_amd64.whl
Size 20.7 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
100c7b6910f7f490c3ee7f860031191eb0d9aaf97e5b00204c9ed84191b44805
BLAKE2b-256 checksum
How to use checksums
e457dfe3de9af9c09b6d9a2ac2a9cb21fefee5118afca181f85a581a95da8c0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL magika-2.0.0rc0-cp38-abi3-musllinux_1_2_x86_64.whl
Size 21.9 MB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
58d91903a491e96b0187536349044a6896a628343ca241d1d8a441a86f253c47
BLAKE2b-256 checksum
How to use checksums
8b90a060d5e9f651556fa0d2bdbc996721f9bd59ff2ce6b1af917dc521a9a90d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-musllinux_1_2_aarch64.whl

Download URL magika-2.0.0rc0-cp38-abi3-musllinux_1_2_aarch64.whl
Size 20.3 MB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
ba27acdf6dbc0a0d6bf657347c969b0dd4531767234b4515bf59af2737793877
BLAKE2b-256 checksum
How to use checksums
6ff48901cfe23139c286dfbd0d0d26d624fa0bf86fd92606e594e93217ac3537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-manylinux_2_31_riscv64.whl

Download URL magika-2.0.0rc0-cp38-abi3-manylinux_2_31_riscv64.whl
Size 19.5 MB
Tags CPython 3.8 Linux glibc 2.31+ RISC-V 64 abi3
SHA-256 checksum
How to use checksums
77e8302c096241e5441fef4fce216cf7f21e6dbd1a338b2531e4dcb80a8578b1
BLAKE2b-256 checksum
How to use checksums
cb5572ee18e2ecaad08990f95feb6e0377e730e7e32dc54abb44cfdce7b0672d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-manylinux_2_28_x86_64.whl

Download URL magika-2.0.0rc0-cp38-abi3-manylinux_2_28_x86_64.whl
Size 21.6 MB
Tags CPython 3.8 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
9bc359f3dbda614c21832299f1f3f1b1bf680ac6b5d6525ebb626b31a1868a88
BLAKE2b-256 checksum
How to use checksums
fd56e0c549c2a72595290e77170359e0d738f6119ac70ddb2834ad32512e5cde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-manylinux_2_28_aarch64.whl

Download URL magika-2.0.0rc0-cp38-abi3-manylinux_2_28_aarch64.whl
Size 20.1 MB
Tags CPython 3.8 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
d5bbfb7518135ff42d002c4eb1a2d13bb4b9ccf03d59ce4d4a85af18d5fa2e6c
BLAKE2b-256 checksum
How to use checksums
08cd05672fbeb8f181898835b90719761a7014161cbe2f8dafdb1b7aca25ab45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl

Download URL magika-2.0.0rc0-cp38-abi3-manylinux2014_armv7l.manylinux_2_17_armv7l.whl
Size 19.3 MB
Tags CPython 3.8 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
5fde608d33d4f7d2dea39e23fa6feb75e914ecaa5cd39ec7b8df0e57d1e8a49f
BLAKE2b-256 checksum
How to use checksums
86b678f18f98af9a192ebfdfadf5a168e3de4c14fdceaade81abd65752ea16b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-macosx_11_0_arm64.whl

Download URL magika-2.0.0rc0-cp38-abi3-macosx_11_0_arm64.whl
Size 23.3 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fba6c347f5a5d54675da86933891032cf837d98def29f870c5e12b8a84efc58f
BLAKE2b-256 checksum
How to use checksums
9fe09e89d6daade1bc382d58dcaf6d714f275a9d80b4c09924341166ce2d8c0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / magika-2.0.0rc0-cp38-abi3-macosx_10_12_x86_64.whl

Download URL magika-2.0.0rc0-cp38-abi3-macosx_10_12_x86_64.whl
Size 25.2 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
001914b39e8be6ea86a2991979e56a958d3de45405a8a8db35def9cd571c97e1
BLAKE2b-256 checksum
How to use checksums
5be51edf2db78e898918c207784ac579a3f5c6ee93750ca05b3093352d51d786
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for magika 2.0.0rc0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 10 files in this release have been uploaded with provenance metadata.

Select from 10 files

Attestation for magika-2.0.0rc0-cp38-abi3-win_arm64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page