m2cgen

m2cgen converts machine learning models into native code for multiple programming languages without runtime dependencies.

github.com/BayesWitnesses/m2cgen
m2cgen homepage screenshot

About m2cgen

m2cgen (Model 2 Code Generator) is a lightweight Python library that transpiles trained statistical models into native source code for a range of programming languages, including C, C#, Dart, F#, Go, Haskell, Java, JavaScript, PHP, PowerShell, Python, R, Ruby, Rust, Visual Basic and Elixir. The generated code is intended to have zero dependencies, so a trained model can be embedded where a full Python stack is not available. It can be used from Python or through a command-line interface, and requires Python 3.7 or newer.

Supported models come from scikit-learn, StatsModels, lightning, LightGBM and XGBoost, covering classification and regression across linear, SVM, tree, random forest and boosting families. Some model variants are only partially covered: for example, LGBM random-forest models are supported with the rf booster only, and XGBoost classifiers and regressors with the gbtree (including boosted forests) or gblinear boosters only. The project states that compatibility is guaranteed for the package versions tested in CI, and that other versions may work but are untested. Classification output follows the conventions of the underlying libraries, such as decision_function and predict_proba.

Key features

  • Transpiles trained models into native code for Java, C, Python, Go, JavaScript, C#, R, Rust and others
  • Supports scikit-learn, StatsModels, lightning, LightGBM and XGBoost models
  • Covers classification and regression across linear, SVM, tree, forest and boosting families
  • Classification output matches decision_function and predict_proba conventions
  • Usable from a Python API or a command-line interface
  • Provides a Docker setup for the pre-PR check command
Best for: Developers who need to embed trained statistical models as dependency-free native code in applications written outside Python.
Good for
  • Open-source repository with a broad set of target programming languages
  • Generated code is described as having zero dependencies
  • Model compatibility listed across several popular ML libraries
Watch out for
  • Requires Python 3.7 or newer
  • Some model variants are limited to specific boosters, such as LGBM rf-only and XGBoost gbtree/gblinear
  • Guaranteed compatibility applies only to package versions tested by CI; other versions are untested

m2cgen at a glance

Type
Open-source project
Pricing
Not confirmed. Check the site
Open source
Yes · Source code
Language
English
Last checked
Oct 6, 2026 · Online when checked
Listed
Oct 5, 2026

m2cgen alternatives

Tools and sites you could use instead, ranked by how closely they match.

All 24 alternatives

Popular in ML Training & Optimization

Well-known listings from the same topic.

All 75

m2cgen FAQ

Which Python versions does m2cgen support?
The supported Python version is 3.7 or newer.
Can m2cgen be used without writing Python code?
Yes. A command-line interface (CLI) is documented in addition to the Python usage.
Are all model variants of a library fully supported?
No. Some are restricted; for example, LGBM random-forest models require the rf booster, and XGBoost classifiers and regressors support only the gbtree (including boosted forests) or gblinear boosters.
Is something wrong or out of date?

Tell us and an editor will check it.

Own this website?

Claim the listing and suggest updates yourself. An editor checks every claim first.

Claim this listing