{"id":37692303,"url":"https://github.com/ebranlard/matlab2python","last_synced_at":"2026-01-16T12:43:26.918Z","repository":{"id":41084570,"uuid":"171057056","full_name":"ebranlard/matlab2python","owner":"ebranlard","description":"Simple matlab2python converter","archived":false,"fork":false,"pushed_at":"2023-11-30T16:36:28.000Z","size":120,"stargazers_count":321,"open_issues_count":7,"forks_count":74,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-10-12T00:50:15.404Z","etag":null,"topics":["matlab","python","transpiler"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ebranlard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.TXT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-02-16T22:07:36.000Z","updated_at":"2025-10-07T18:06:02.000Z","dependencies_parsed_at":"2023-01-21T06:45:55.981Z","dependency_job_id":"c7c8221e-5bd2-41d9-9a57-845049208c9c","html_url":"https://github.com/ebranlard/matlab2python","commit_stats":{"total_commits":31,"total_committers":3,"mean_commits":"10.333333333333334","dds":0.09677419354838712,"last_synced_commit":"2fd204515c056d1f4e8ce6cdfbbb97e9bcd7cc55"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ebranlard/matlab2python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebranlard%2Fmatlab2python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebranlard%2Fmatlab2python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebranlard%2Fmatlab2python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebranlard%2Fmatlab2python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ebranlard","download_url":"https://codeload.github.com/ebranlard/matlab2python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebranlard%2Fmatlab2python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matlab","python","transpiler"],"created_at":"2026-01-16T12:43:26.401Z","updated_at":"2026-01-16T12:43:26.909Z","avatar_url":"https://github.com/ebranlard.png","language":"Python","funding_links":["https://www.buymeacoffee.com/hTpOQGl"],"categories":[],"sub_categories":[],"readme":"[![Build status](https://github.com/ebranlard/matlab2python/workflows/Tests/badge.svg)](https://github.com/ebranlard/matlab2python/actions?query=workflow%3A%22Tests%22)\n\u003ca href=\"https://www.buymeacoffee.com/hTpOQGl\" rel=\"nofollow\"\u003e\u003cimg alt=\"Donate just a small amount, buy me a coffee!\" src=\"https://warehouse-camo.cmh1.psfhosted.org/1c939ba1227996b87bb03cf029c14821eab9ad91/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d4275792532306d6525323061253230636f666665652d79656c6c6f77677265656e2e737667\"\u003e\u003c/a\u003e\n\n# matlab2python\n\nA python script to convert matlab files or lines of matlab code to python. This project is in alpha phase. \nThis implementation relies heavily on the project [SMOP](http://github.com/victorlei/smop/) by Victor Leikehman. \nThe current implementation wraps around SMOP, with the following differences: \n\n- It attempts to produce code that does not rely on `libsmop`, but only on usual python modules such as `numpy`.\n- It uses typical shortcuts such as `np` instead of `numpy`.\n- It attemps to reindex arrays and loops, starting from 0 instead of 1.\n- It doesn't use the external classes `matlabarray` and `cellarray` from `libsmop`\n- Basic support for Matlab classes is added. The properties declared in the body of the class are initialized in the constructor.\n- As a consequenc of all the above, the resulting code is \"less safe\" but maybe slightly closer to what a user would write.\n\nThis implementation is made straightforward, since it basically use another backend script than the one used by SMOP, here called `smop\\backend_m2py.py`. \nSome function replacements were added directly there. \nAdditional support for classes, import modules and other fine-tuning replacements (or hacks...) are done in the file `matlabparser\\parser.py`.\n\n\n## Install\nThe code is written in python, you can access it as follows:\n```bash\ngit clone https://github.com/ebranlard/matlab2python\ncd matlab2python\n# install dependencies\npython -m pip install --user -r requirements.txt \n# make the packages available from any directory\npython -m pip install -e .  \n#Optional: run tests\npytest\n#Optional: try it directly\npython matlab2python.py tests/files/fSpectrum.m -o fSpectrum.py\n```\n\n## Usage\n\n### Main script\nThe main script at the root of the repository is executable and has a couple of command line flags (some of them taken directly from SMOP). \nTo convert the file `file.m` to `file.py`, simply type:\n```bash\npython path/to/matlab2python.py file.m -o file.py\n```\nwhere `path/to` is the path to the script `matlab2python.py`\n\n\n### From python\nThe python package can also be used directly to perform conversion of files or lines of code.\n```python\nimport matlabparser as mpars\n# --- Convert a matlab file \npylines = mpars.matlab2python('path/to/file.m', output='file.py')\n\n# --- Convert matlab lines (string or list of strings)\nmlines=\"\"\"# a comment\nx = linspace(0,1,100);\ny = cos(x) + x**2;\n\"\"\"\npylines = mpars.matlablines2python(mlines, output='stdout')\n```\n\n\n## Should I use this\n\nIf you need a script that performs the obvious conversions from matlab to python, `matlab2python` will hopefully work for you.\nThese conversions are for instance: \n\n- syntax (`def`, `if`, `for`, `__init__`, no more `end`)\n- indentation\n- parenthesis to brackets\n- simple builtin functions replacements (`fprintf`, `disp`, `error`, `fopen`)\n- simple numpy replacements like `zeros(3,4)` to `np.zeros((3,4))`, or `cosd(x)`, to `np.cosd(np.pi/180 x)`\n- other misc functions like `strcmp`, `strrep`, `reshape` replaced by their python , \n- etc\n\nAs mentioned above, [SMOP](http://github.com/victorlei/smop/) does a great job to produce safe code.\nYet, neither `SMOP` nor `matlab2python` will generate code that is production-ready (it might in some cases). \nMost of the time, the user will have to go through the code and perform adjustements and some rewritting. \nIn fact, `matlab2python` will likely be slightly worse than SMOP in producing a code that works out of the box.\nBut at the end, the code produced by `matlab2python` should require less refactoring and help the user in its conversion.\nAs mentioned by the author of SMOP, it is difficult not to hide the matlab flavor from the code that is generated and it's also difficult to fully convert the code without introducing wrapped classes such that `matlabarray`. The implemenation of `matlab2python` attempts to do that, at the price of less safety.\n\nI've written this wrapper script for my own needs. I was ready to convert manually a bunch of matlab scripts, but I thought I could have a script to automate some of the simple conversions and formatting. I started a quick and dirty implementation before discovering `SMOP`. At the end, I merged my quick and dirty implemenation with the more powerful parsing framework used by SMOP. Hopefully this can be useful to someone else! If so, feel free to contribute. \n\n\n\n# Contributing\nAny contributions to this project are welcome! If you find this project useful, you can also buy me a coffee (donate a small amount) with the link below:\n\n\n\u003ca href=\"https://www.buymeacoffee.com/hTpOQGl\" rel=\"nofollow\"\u003e\u003cimg alt=\"Donate just a small amount, buy me a coffee!\" src=\"https://warehouse-camo.cmh1.psfhosted.org/1c939ba1227996b87bb03cf029c14821eab9ad91/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d4275792532306d6525323061253230636f666665652d79656c6c6f77677265656e2e737667\"\u003e\u003c/a\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Febranlard%2Fmatlab2python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Febranlard%2Fmatlab2python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Febranlard%2Fmatlab2python/lists"}