[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.jsonpython/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
Magika.get_model_content_types()support:- Returns the sorted list of all possible raw model output labels (
target_labels_spacefrommodel_config.min.json, plus"undefined"— 215 labels instandard_v3_3). - In
rust/lib/src/model.rs,CONFIG.labelsalready contains the 214 target labels in[LabelConfig; 214], butCONFIGispub(crate).
- Returns the sorted list of all possible raw model output labels (
Magika.get_output_content_types()support:- Returns the sorted list of all possible effective output labels:
- All
target_labels_spacelabels mapped throughoverwrite_map(i.e.LabelConfig::content_typeinCONFIG.labels), unioned with - Special ruled labels:
directory,empty,symlink,txt,unknown(216 labels total instandard_v3_3).
- All
- Returns the sorted list of all possible effective output labels:
Static
TypeInfolookup by label (including"undefined"):- In Python,
MagikaResult.prediction.dlandMagikaResult.prediction.outputareContentTypeInfoobjects with:label:strmime_type:strgroup:strdescription:strextensions:list[str]is_text:bool
rust/libalready haspub struct TypeInfoandContentType::info(&self) -> &'static TypeInfo.- However, when
FileTypeisFileType::Ruled(...), there is no raw DL prediction, which Magika represents asdl.label = "undefined"(mime_type = "application/octet-stream",group = "undefined",description = "Undefined",extensions = [],is_text = false). CurrentlyContentType::Undefineddoes not exist inrust/lib/src/content.rs(ContentTypehas 320 variants, omittingundefined).
- In Python,
Proposed Rust API Changes
- Add
ContentType::Undefined(with its correspondingTypeInfoentry fromcontent_types_kb.min.json) torust/lib/src/content.rs(viarust/gen), or provide a helper to retrieveTypeInfofor"undefined". - Expose public functions/methods in
magika(rust/lib) for:magika::model_content_types() -> &'static [ContentType](or an iterator overCONFIG.labelsrawContentTypes +ContentType::Undefined).magika::output_content_types() -> &'static [ContentType](or an iterator overCONFIG.labelsmappedContentTypes +Directory,Empty,Symlink,Txt,Unknown).
- With this (plus
PredictionMode/OverwriteReasoningh-issue-1.md),rust/pyo3can directly return fullTypeInfometadata and implementget_model_content_types()/get_output_content_types()in Rust, allowing us to deletepython/src/magika/config/model_config.min.jsonandpython/src/magika/config/content_types_kb.min.jsoncompletely.
Source: google/magika