Skip to content

Files

Latest commit

0689a2e · Mar 24, 2025

History

History
48 lines (36 loc) · 2.51 KB

README.md

File metadata and controls

48 lines (36 loc) · 2.51 KB
MPython logo.

MPython Template

This repo is a simple example of wrapping Matlab projects in Python using Matlab Compiler and MPython

To wrap your project from Github

0. Prerequisites.

This requires Matlab Compiler, as well as a version of Matlab Runtime compatible with your version of Matlab.

git clone git@github.com:MPython-Package-Factory/mpython-template.git YOUR_PROJECT_NAME
cd YOUR_PROJECT_NAME

...to target the right project URL and configure the name of the Python package

python_package_name = 'example_project'; 
matlab_project_url  = 'https://github.com/MPython-Package-Factory/example-project-matlab.git'; 

3. Wrap your project

cd .mpython                     # Move to .mpython
matlab -batch "wrap_project"    # Create the Python wrapper
cd ..                           # Move back to the main folder

4. Finally, install your package with Pip and try it out

python3 -m pip install -e .    # Install the package in developper mode
python3 -c "import example_project"

Configuring the code generation

MPython will generate Python code using certain templates for common code structures (e.g., function signature or class definition).

A full list of the existing templates can be found in mpython/templates.

You can customize these defaults templates by copying them to your .mpython/templates and editing them (as for this custom docstring template).