Practical overview
When it fits
Use M2Cgen when a trained model is among the supported estimators and you want generated source code for integration into a target-language application. Review output semantics and tested package versions before relying on the generated function in an application.
Who it is for
- Python practitioners exporting supported trained models into another programming language.
- Application developers who want model inference logic as source code rather than a separate serving runtime.
- Teams working in environments where adding runtime dependencies is difficult.
Documented uses
- Convert a supported fitted estimator into native source code for a selected target language.
- Generate code from a serialized model using the command-line interface.
- Embed model inference logic in an application written in a supported language.
Requirements & limits
The repository advertises an MIT license. The README specifies Python 3.7 or later and gives pip as the installation route.
- Model support is specific to estimator families and implementations; consult the README’s supported-model table.
- Classification outputs differ by model family: decision scores for linear and SVM cases, and class probabilities for listed tree, forest and boosting classifiers.
- The README identifies tested package versions through its CI requirements and says other versions are untested.
- CLI use of serialized models depends on importable top-level model classes.
- The README notes that ensemble generation may encounter Python recursion limits.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Export a fitted scikit-learn model to Java
Generate Java source representing a fitted linear regression model using the documented Python interface.
Before you start
- Python 3.7 or later
- m2cgen installed with pip
- A fitted scikit-learn LinearRegression estimator
Steps
Import m2cgen and the scikit-learn model class in Python.
Fit the LinearRegression estimator on training data.
Call m2cgen.export_to_java(estimator) to generate Java code.
Expected outcome
A Java source string containing a model class with a score method, as shown in the project README.
Guide limitations
- The example covers linear regression; support for other models and languages depends on the project’s supported-model and language lists.
Generate code from a serialized model with the CLI
Use the m2cgen CLI to generate source code from a serialized model object.
Before you start
- m2cgen installed
- A model object serialized using Python’s pickle protocol
- The model’s classes defined at the top level of an importable module in the unpickling environment
Steps
Provide the serialized model file to the m2cgen command.
Specify the output language with the --language option.
Optionally set documented naming, indentation or recursion-limit options.
Expected outcome
Generated source code in the selected language.
Guide limitations
- The README does not provide a complete model-training, serialization or deployment procedure.
- Deserialization requires the model classes to be importable in the environment.
Compare options for Model inference and serving
These projects document a common task and share a project role. This is a source-based comparison, not an execution benchmark or a guarantee of interchangeability.
| Project | Documented purpose | Platform | Access and requirements |
|---|---|---|---|
| M2Cgen | Convert a supported fitted estimator into native source code for a selected target language. | CLI | The repository advertises an MIT license. The README specifies Python 3.7 or later and gives pip as the installation route. |
| Hyperpose | Customize pose-estimation architectures and datasets. | Docker, Linux, macOS, Windows | |
| Multi Task Nlp | Define multiple tasks and their data and model settings in a YAML file. | Linux, macOS, Windows | The project is an open-source library under the Apache-2.0 license, distributed through its public GitHub repository. |
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 14 October 2026
- Original website title
- BayesWitnesses/m2cgen · Official homepage title · retained in its source language

