TypeScript icon, indicating that this package has built-in type declarations

0.2.13 • Public • Published

Magika TypeScript/JavaScript library

Use Magika in the browser or in Node!

Installing MagikaJS

npm install magika

Using MagikaJS

Simple usage in Node:

import { readFile } from "fs/promises";
import { MagikaNode as Magika } from "magika";

const data = await readFile("some file");
const magika = new Magika();
await magika.load();
const prediction = await magika.identifyBytes(data);

Simple usage in the browser:

import { Magika } from "magika";

const file = new File(["# Hello I am a markdown file"], "");
const fileBytes = new Uint8Array(await file.arrayBuffer());
const magika = new Magika();
await magika.load();
const prediction = await magika.identifyBytes(fileBytes);

For more, see our documentation.

Commmand-line tool

Please use the official CLI (with pip install magika) as it can perform batch processing and search for files recursivelyw. Read more about that in the main README. This one is useful to load the TensorflowJS model and see that it works as expected.

Install it with npm install -g magika. You can then run it by executing magika-js <some files>

Magika JS - file type detection with ML.

  paths                      Paths of the files to detect

  --json-output              Format output in JSON
  --model-url <model-url>    Model URL (default: "")
  --config-url <config-url>  Config  URL (default: "")
  -h, --help                 display help for command

Reporting false positives

Please open an issue on Github.


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

author = {Fratantonio, Yanick and Bursztein, Elie and Invernizzi, Luca and Zhang, Marina and Metitieri, Giancarlo and Kurt, Thomas and Galilee, Francois and Petit-Bianco, Alexandre and Farah, Loua and Albertini, Ange},
title = {{Magika content-type scanner}},
url = {}

Loading the model and configuration

MagikaJS is designed flexible in how you provide the model and configuration file to it.

Both the Node and browser versions accept URLs to asyncronously load these two assets.

await magika.load({
        modelURL: "https://...",
        configURL: "https://...",

The Node version also allows to load local files.

await magika.load({
        modelPath: './assets/...',
        configPath: './assets/...'


Using the model hosted On Github:

yarn install
yarn run build
yarn run bin --

Using the local model:

yarn install
yarn run build
(cd ../website; yarn install; yarn run dev) &
yarn run bin --model-url http://localhost:5173/magika/model/model.json --config-url http://localhost:5173/magika/model/config.json ../tests_data/mitra/*



yarn install
yarn run build
yarn run test

Package Sidebar


npm i magika

Weekly Downloads






Unpacked Size

103 kB

Total Files


Last publish


  • lucainvernizzi
  • reyammer