MJML Python Implementation

0.12.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

from mjml import mjml2html

mjml_template = '''
<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-text font-size="20px" color="#F45E43" font-family="Open Sans">Hello, MJML!</mj-text>
        <mj-button href="https://mjml.io/" background-color="#F45E43">Learn More</mj-button>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>
'''

result = mjml2html(mjml_template)

if result.errors:
    print("MJML compilation errors:", result.errors)
else:
    print(result.html)

view raw JSON →