A Python wrapper for MRML (Rust port of MJML).
Project description
mjml-python
Compile MJML at runtime without a Node.js service, external API, or subprocess.
mjml-python is a Python wrapper around the Rust MJML engine MRML, a high-performance port of the official MJML.
Why
Using MJML traditionally requires either:
- running the Node.js-based MJML CLI as a subprocess, or
- calling an external MJML API service.
Both approaches add memory overhead, latency, operational complexity, and cost.
From MRML:
A Node.js server rendering an MJML template takes around 20 MB of RAM at startup and 130 MB under stress test. In Rust, less than 1.7 MB at startup and a bit less that 3 MB under stress test. The Rust version can also handle twice as many requests per second.
By embedding the Rust engine directly, mjml-python avoids all external dependencies while retaining full MJML compatibility.
Installation
Install from PyPI:
pip install mjml-python
Usage
Call mjml2html() with your MJML string:
from mjml import mjml2html
html = mjml2html(
'''
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-image width="100px" src="/assets/img/logo-small.png"></mj-image>
<mj-divider border-color="#F45E43"></mj-divider>
<!-- Say hello to the user -->
<mj-text font-size="20px" color="#F45E43" font-family="Open Sans">Hello World</mj-text>
</mj-column>
</mj-section>
<mj-section>
<mj-column>
<mj-social font-size="15px" icon-size="30px" mode="horizontal">
<mj-social-element name="facebook" href="https://mjml.io/">
Facebook
</mj-social-element>
<mj-social-element name="google" href="https://mjml.io/">
Google
</mj-social-element>
<mj-social-element name="twitter" href="https://mjml.io/">
Twitter
</mj-social-element>
</mj-social>
</mj-column>
</mj-section>
</mj-body>
</mjml>
''',
disable_comments=True,
social_icon_origin="https://example.com",
fonts={
"Open Sans": "https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700",
"Ubuntu": "https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700",
}
)
Example using Django templates
from django.core.mail import send_mail
from django.template.loader import render_to_string
from mjml import mjml2html
context = {'foo': 'bar'}
text_message = render_to_string('my_text_template.txt', context)
html_message = mjml2html(render_to_string('my_mjml_template.mjml', context))
send_mail(
'Subject here',
text_message,
'from@example.com',
['to@example.com'],
fail_silently=False,
html_message=html_message,
)
Configuration Options
mjml-python supports the following options:
| Name | Type | Default value | Comment |
|---|---|---|---|
disable_comments |
bool |
False |
Strip comments out of rendered HTML |
social_icon_origin |
str | None |
None |
Custom URL origin for social icons. Icon name is appended (e.g. facebook.png). |
fonts |
dict[str, str] | None |
None |
Fonts imported in the HTML rendered by MJML. |
include_loader |
Callable[[str], str] | None |
None |
Fetch the included template using the path attribute. |
Default fonts (used when fonts=None):
{
"Open Sans": "https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700",
"Droid Sans": "https://fonts.googleapis.com/css?family=Droid+Sans:300,400,500,700",
"Lato": "https://fonts.googleapis.com/css?family=Lato:300,400,500,700",
"Roboto": "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700",
"Ubuntu": "https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700",
}
Why choose mjml-python instead of other MJML packages?
-
Simple, Pythonic API – a single
mjml2html()function that takes plain keyword arguments and returns a clean HTML string. No need to construct parser/render option objects or work with custom result classes. -
Batteries-included defaults – sensible defaults for fonts, comment handling, and include behavior, so most templates work with zero configuration.
-
Flexible include loader – pass a Python callable to handle
<mj-include>however you like (filesystem, database, HTTP, etc.) without learning MRML’s multiple loader types. -
Minimal surface area – intentionally focused on the common case: take MJML input → return production-ready HTML. No extra abstractions.
-
No external services or subprocesses required – rendering is performed entirely inside the Python extension using the embedded Rust MJML engine. No Node.js installation, MJML CLI, or HTTP API needed.
-
Stable wheel builds – lightweight ABI-3 wheels for all major platforms (CPython 3.7+), fast installation, and no compilation required on typical environments.
In short: mjml-python is ideal when you want a straightforward, Python-friendly way to render MJML without dealing with the full MRML configuration surface or external tooling.
Development
With Nix:
nix-shell
With Python 3.7+, Rust and Cargo installed:
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
maturin develop
python -m unittest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mjml_python-1.4.0.tar.gz.
File metadata
- Download URL: mjml_python-1.4.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cab9be42ae1da86c5addb50a1262c9f3ae34d1cf3d0a00d8740ceac7237e4f72
|
|
| MD5 |
2a99603cb9b7d8296cf47a4940b98b35
|
|
| BLAKE2b-256 |
9363df6509ea81ecb8f59885b8dd9b2395e52db34b5da6c7d6511b44de0a48e1
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0.tar.gz:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0.tar.gz -
Subject digest:
cab9be42ae1da86c5addb50a1262c9f3ae34d1cf3d0a00d8740ceac7237e4f72 - Sigstore transparency entry: 1269703206
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type:
File details
Details for the file mjml_python-1.4.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: mjml_python-1.4.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 435.8 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76399e51b5d3e5068836322ce2439c43b1c18a538dcf7a8637bdead356a76d09
|
|
| MD5 |
929375be1cfcda929eea2cdccdb56878
|
|
| BLAKE2b-256 |
3b356146c5941207605f10b22b915032bb67d53c4039fc3d2866575815be4760
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0-cp38-abi3-win_amd64.whl:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0-cp38-abi3-win_amd64.whl -
Subject digest:
76399e51b5d3e5068836322ce2439c43b1c18a538dcf7a8637bdead356a76d09 - Sigstore transparency entry: 1269704667
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type:
File details
Details for the file mjml_python-1.4.0-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mjml_python-1.4.0-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 688.3 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f6f1cb5a67780c4ca1931baa05c287ac179f304e40862bb55279b285b66ced4
|
|
| MD5 |
dc576d9ec0f2b6405cfceb76b7002fdb
|
|
| BLAKE2b-256 |
6f77d31b1af6a4226c4b6a77ef0215eb575f49e767282e6f8a5c58795e15fbf6
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0-cp38-abi3-musllinux_1_2_x86_64.whl:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0-cp38-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
0f6f1cb5a67780c4ca1931baa05c287ac179f304e40862bb55279b285b66ced4 - Sigstore transparency entry: 1269703777
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type:
File details
Details for the file mjml_python-1.4.0-cp38-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: mjml_python-1.4.0-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 775.0 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e7d1dc554349af76a03516e321f6515a32a0a9aef41134ebce4966c39bc42ac
|
|
| MD5 |
93f26d05784234e06cde43f78aff729c
|
|
| BLAKE2b-256 |
822d1ef1a38b08d9676c5c8dba50a09fb1030b851db43a443118fc22a027ccd5
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0-cp38-abi3-musllinux_1_2_aarch64.whl:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0-cp38-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
8e7d1dc554349af76a03516e321f6515a32a0a9aef41134ebce4966c39bc42ac - Sigstore transparency entry: 1269704085
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type:
File details
Details for the file mjml_python-1.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mjml_python-1.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 608.0 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e26a18634dd272d69c4af0b89369f51ea6c40c315a8fa1b5af15b00aec00376
|
|
| MD5 |
e02ea69996c1942d97090fb300b5ef1c
|
|
| BLAKE2b-256 |
79daff5aa0a9058f329ec67f61f500ed14472bb40442b45119987a7da262393f
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
5e26a18634dd272d69c4af0b89369f51ea6c40c315a8fa1b5af15b00aec00376 - Sigstore transparency entry: 1269703478
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type:
File details
Details for the file mjml_python-1.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: mjml_python-1.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 598.6 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9daf8f043335bd17adca7b46c5bbdaf2923ee46b666357c8bb57abe6ebf6d56
|
|
| MD5 |
859092c9883ca1863a81bd2951774ec1
|
|
| BLAKE2b-256 |
c6a092553f26360c97b172a45ce11f9dcdd72ad16b366b31067439702bd18a92
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
e9daf8f043335bd17adca7b46c5bbdaf2923ee46b666357c8bb57abe6ebf6d56 - Sigstore transparency entry: 1269704902
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type:
File details
Details for the file mjml_python-1.4.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: mjml_python-1.4.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 548.7 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bb6a49694faca9595a57887dc474843417e05a0337fe42155a314fcd07004a7
|
|
| MD5 |
69ca2ad42bbcc0a2709ce111ff7a9c4a
|
|
| BLAKE2b-256 |
d28c7f34854e5b225e4b6e5c2aea707aae9e9e7fbfc41505c44fc1e428af0d24
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
1bb6a49694faca9595a57887dc474843417e05a0337fe42155a314fcd07004a7 - Sigstore transparency entry: 1269704396
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type:
File details
Details for the file mjml_python-1.4.0-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: mjml_python-1.4.0-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 560.6 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eda0d1f3893c93f6be7db9e2dc1867eb5c8e9f8e985ca4a58f83b286acbb9503
|
|
| MD5 |
8f51628e748de535693693937c422c3a
|
|
| BLAKE2b-256 |
ea8bf6c2a1cae0fc4537ab71bf4ea10f95473d0c0c04c3b6f2053a018460fa44
|
Provenance
The following attestation bundles were made for mjml_python-1.4.0-cp38-abi3-macosx_10_12_x86_64.whl:
Publisher:
CI.yml on mgd020/mjml-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mjml_python-1.4.0-cp38-abi3-macosx_10_12_x86_64.whl -
Subject digest:
eda0d1f3893c93f6be7db9e2dc1867eb5c8e9f8e985ca4a58f83b286acbb9503 - Sigstore transparency entry: 1269705075
- Sigstore integration time:
-
Permalink:
mgd020/mjml-python@c824492826d400ff805da5f8313ab44e2cab369d -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/mgd020
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@c824492826d400ff805da5f8313ab44e2cab369d -
Trigger Event:
release
-
Statement type: