m2cgen logo

m2cgen

Free

A CLI tool which allows to transpile trained classic ML models into a native code of various programming languages with zero dependencies including C.

FreeFree tier
Outputs: code
Type
Open Source

About m2cgen

m2cgen (Model 2 Code Generator) is a lightweight library that provides an easy way to transpile trained statistical models into native code (Python, C, Java, Go, JavaScript, Visual Basic, C#, PowerShell, R, PHP, Dart, Haskell, Ruby, F#, Rust, Elixir). It supports models from scikit-learn, statsmodels, lightning, XGBoost, and LightGBM. The generated code has zero dependencies, making it suitable for embedded systems and environments where Python is not available. It can be used as both a Python library and a CLI tool.

Key Features

Transpile models to 16+ programming languages including C, Java, Python, Go, JavaScript, Visual Basic, C#, PowerShell, R, PHP, Dart, Haskell, Ruby, F#, Rust, Elixir
Generated code has zero external dependencies
Supports classification and regression models from scikit-learn, statsmodels, lightning, XGBoost, and LightGBM
Can be used as a Python library or from the command line
Lightweight and easy to integrate into workflows

Pros & Cons

Pros
  • Supports a wide variety of output languages, covering many platforms
  • Zero-dependency output makes deployment simple and portable
  • Compatible with popular ML frameworks like scikit-learn, XGBoost, and LightGBM
  • Open source with permissive license (MIT)
  • Easy to use via CLI or Python API
Cons
  • Does not support deep learning models (e.g., neural networks)
  • Generated code may not be optimized for all target platforms or hardware
  • Limited to models from supported libraries; custom models cannot be transpiled

Best For

Embedding ML models in resource-constrained or embedded environmentsDeploying models to production without requiring a Python runtimeConverting models for use in languages like Java, C#, or JavaScript for enterprise applicationsGenerating standalone code for devices and IoT systems