#1480·magika

[magika-lib] Expose static content-type metadata and model/output label spaces to eliminate Python JSON configs

Author: reyammerCreated Sep 18, 2026Updated Sep 18, 2026

Context

In the Python pyo3 bindings (rust/pyo3 + python/), we want python/ to be a thin wrapper around magika-lib (rust/lib) without carrying duplicate configuration files.

Currently, python/src/magika/ still has to bundle and load two JSON files at runtime in Magika.__init__:

  • python/src/magika/config/model_config.min.json
  • python/src/magika/config/content_types_kb.min.json

These JSON files are already compiled into rust/lib (rust/lib/src/content.rs and rust/lib/src/model.rs via rust/gen), but because a few static introspection APIs are not publicly exposed by magika-lib, Python still has to read the JSON files from disk.

What Python Needs from magika-lib

  1. Magika.get_model_content_types() support:

    • Returns the sorted list of all possible raw model output labels (target_labels_space from model_config.min.json, plus "undefined" — 215 labels in standard_v3_3).
    • In rust/lib/src/model.rs, CONFIG.labels already contains the 214 target labels in [LabelConfig; 214], but CONFIG is pub(crate).
  2. Magika.get_output_content_types() support:

    • Returns the sorted list of all possible effective output labels:
      • All target_labels_space labels mapped through overwrite_map (i.e. LabelConfig::content_type in CONFIG.labels), unioned with
      • Special ruled labels: directory, empty, symlink, txt, unknown (216 labels total in standard_v3_3).
  3. Static TypeInfo lookup by label (including "undefined"):

    • In Python, MagikaResult.prediction.dl and MagikaResult.prediction.output are ContentTypeInfo objects with:
      • label: str
      • mime_type: str
      • group: str
      • description: str
      • extensions: list[str]
      • is_text: bool
    • rust/lib already has pub struct TypeInfo and ContentType::info(&self) -> &'static TypeInfo.
    • However, when FileType is FileType::Ruled(...), there is no raw DL prediction, which Magika represents as dl.label = "undefined" (mime_type = "application/octet-stream", group = "undefined", description = "Undefined", extensions = [], is_text = false). Currently ContentType::Undefined does not exist in rust/lib/src/content.rs (ContentType has 320 variants, omitting undefined).

Proposed Rust API Changes

  1. Add ContentType::Undefined (with its corresponding TypeInfo entry from content_types_kb.min.json) to rust/lib/src/content.rs (via rust/gen), or provide a helper to retrieve TypeInfo for "undefined".
  2. Expose public functions/methods in magika (rust/lib) for:
    • magika::model_content_types() -> &'static [ContentType] (or an iterator over CONFIG.labels raw ContentTypes + ContentType::Undefined).
    • magika::output_content_types() -> &'static [ContentType] (or an iterator over CONFIG.labels mapped ContentTypes + Directory, Empty, Symlink, Txt, Unknown).
  3. With this (plus PredictionMode / OverwriteReason in gh-issue-1.md), rust/pyo3 can directly return full TypeInfo metadata and implement get_model_content_types() / get_output_content_types() in Rust, allowing us to delete python/src/magika/config/model_config.min.json and python/src/magika/config/content_types_kb.min.json completely.