{"id":8319,"library":"mjml","title":"MJML Python Implementation","description":"mjml-python is a Python implementation and wrapper around the high-performance Rust MJML engine MRML. It allows compiling MJML markup into responsive HTML without requiring a Node.js runtime, external API calls, or subprocesses. The current version is 0.12.0. Releases are published as needed, often reflecting updates to the underlying MJML standard or significant bug fixes.","status":"active","version":"0.12.0","language":"en","source_language":"en","source_url":"https://github.com/FelixSchwarz/mjml-python","tags":["email","responsive","html","mjml","frontend","template"],"install":[{"cmd":"pip install mjml","lang":"bash","label":"Install the latest version"}],"dependencies":[{"reason":"Used for inlining CSS directly into the HTML output, which is crucial for email client compatibility.","package":"css-inline","optional":false}],"imports":[{"symbol":"mjml2html","correct":"from mjml import mjml2html"}],"quickstart":{"code":"from mjml import mjml2html\n\nmjml_template = '''\n<mjml>\n  <mj-body>\n    <mj-section>\n      <mj-column>\n        <mj-text font-size=\"20px\" color=\"#F45E43\" font-family=\"Open Sans\">Hello, MJML!</mj-text>\n        <mj-button href=\"https://mjml.io/\" background-color=\"#F45E43\">Learn More</mj-button>\n      </mj-column>\n    </mj-section>\n  </mj-body>\n</mjml>\n'''\n\nresult = mjml2html(mjml_template)\n\nif result.errors:\n    print(\"MJML compilation errors:\", result.errors)\nelse:\n    print(result.html)\n","lang":"python","description":"This quickstart demonstrates the core functionality: importing `mjml2html` and passing an MJML string to it. The function returns a `Result` object containing the compiled HTML and any potential errors."},"warnings":[{"fix":"Upgrade to Python 3.9 or newer (e.g., `python -m pip install --upgrade python` if using pyenv, or use a newer system Python). Alternatively, pin `mjml<0.12.0` for older Python versions.","message":"Version 0.12.0 officially dropped support for Python 3.6, 3.7, and 3.8. Users on these Python versions must either upgrade their Python environment or pin to an older `mjml` release.","severity":"breaking","affected_versions":"0.12.0+"},{"fix":"Always install `mjml` directly via `pip install mjml` without pinning `css-inline` to ensure compatible versions are pulled. If issues arise, check your `pip freeze` output for `css-inline` version conflicts.","message":"The `css-inline` dependency underwent incompatible API changes across `mjml` versions. Notably, `0.9.1` pinned `css_inline < 0.10`, while `0.10.0` required `css-inline >= 0.11` (which broke Python 3.6), and `0.11.1` accepted `css_inline >= 0.14`. Mixing `mjml` versions or `css-inline` manually can lead to runtime errors.","severity":"breaking","affected_versions":"0.9.1, 0.10.0, 0.11.x"},{"fix":"Upgrade to `mjml==0.11.0` or newer immediately via `pip install --upgrade mjml`.","message":"A security vulnerability (CVE-2024-26151) was fixed in `v0.11.0` where potentially untrusted input could be rendered directly as HTML, leading to script injection. Users of `0.10.0` are strongly encouraged to upgrade.","severity":"breaking","affected_versions":"0.10.0"},{"fix":"If you need to remove comments, use the `disable_comments=True` option when calling `mjml2html(mjml_string, disable_comments=True)`.","message":"As of v0.12.0, comments within your MJML code (`<!-- comment -->`) will now be preserved and present in the generated HTML output by default. In previous versions, these comments might have been stripped.","severity":"gotcha","affected_versions":"0.12.0+"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install mjml`.","cause":"The `mjml` package has not been installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'mjml'"},{"fix":"Ensure you are calling the `mjml2html` function: `from mjml import mjml2html; html = mjml2html(...)`.","cause":"Attempting to call the `mjml` module directly instead of its `mjml2html` function.","error":"TypeError: 'module' object is not callable"},{"fix":"Ensure you are on a supported operating system and architecture. For Windows, ensure the Visual C++ Redistributable is installed. Try reinstalling with verbose output to check for build errors: `pip install mjml --verbose`.","cause":"This error typically occurs when the underlying Rust binary (MRML) cannot be loaded, usually due to an incompatible system architecture, missing C++ runtime libraries (on Windows), or issues during installation.","error":"RuntimeError: Unable to load shared library 'libmjml_python_core.so' or 'mjml_python_core.dll'"}]}