A Python wrapper for MRML (Rust port of MJML).
Project description
mjml-python
Compile MJML at runtime without an external Node service/process. It is a Python wrapper for MRML (Rust port of MJML).
Why
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.
All of that is without considering http transaction cost when using a node service or process.
How
Install from PyPI:
pip install mjml-python
Import mjml2html
and pass a string to compile:
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,
)
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. |
Notes :
- When
fonts
option is set toNone
, the following default fonts will be used:{ "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", }
Development
python -m venv env
. env/bin/activate
pip install -r requirements.txt
maturin develop
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 Distributions
Built Distributions
Hashes for mjml_python-1.2.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40721112d75b717ccfc4923afb415723c429067f5592a47e71ee84c2fec7c5b8 |
|
MD5 | 9088c70275a42c747cc3d7df4e0fb3d0 |
|
BLAKE2b-256 | 077a70f3f48469dc11bed388c3742b3424f9e525fbb0a8cd9156d52b3cee22cd |
Hashes for mjml_python-1.2.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 280e1b7c24fba62a2e8604d591a7983663c40dd7024a717dc3cce7b8181cd76b |
|
MD5 | 421aef6390ffb7bea0ee4caac333ac5a |
|
BLAKE2b-256 | ddafc6a33c99862a87fccc800711795b067435fc52093bfacf2bd64f029c91a3 |
Hashes for mjml_python-1.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60db403134cb10371fa3f37a08b25bbd1d8f68215c4f9c4ce91ea17fc6a3ca63 |
|
MD5 | cea73cef599ac11f52e264e8699f9d3b |
|
BLAKE2b-256 | bb1c86d4b3d48cd32673a389776fe2f0334a2d31bbe9085af6d42cf8e3122654 |
Hashes for mjml_python-1.2.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1638625d2279e273c2bc8235883ae5996e81778d820822d3ac38b12228b70d6d |
|
MD5 | b9bafb95daac00c371fed8a9579f2e1c |
|
BLAKE2b-256 | 4ca2bcd6fd5c137a79ef5f659e0f57320fd7f25a48d7cbd7664b1507ac0d8ae8 |
Hashes for mjml_python-1.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caaab46f9111831390df521370718bfc385baba257adb9861a62ee378030bb2e |
|
MD5 | 762e9bfaa571be896112653e11540996 |
|
BLAKE2b-256 | 03a8aabb6d012ea75a5236bc7c414598784a140619842dc27981fd534d715578 |
Hashes for mjml_python-1.2.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c347288012f3d2ce3657ff173cdbbe3ccce4f0d8d6c001842038c21aa921b61 |
|
MD5 | 15a3498924740245710f19b59d912cc0 |
|
BLAKE2b-256 | f92215a03ea904c696008494b5cfedb8bbf6d759a771dc49bc06c15da85ef9ed |
Hashes for mjml_python-1.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec0a2c64d3a19260a9ff9eeacdfb5c210a9369f5de96e5085e506f7df17cc928 |
|
MD5 | 62138de16322ee4c7896deb9487f3291 |
|
BLAKE2b-256 | c5972cc36dd42ce7e91d98bcfd351da30b808e37ab79952017dec0ff72270b71 |
Hashes for mjml_python-1.2.1-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70ee77a4b5882ec4603ef0ba3d868cfe5a72cf13fdbf34c28f5f608ee2f81a54 |
|
MD5 | cb92cf378d859349758ad003e018e6b6 |
|
BLAKE2b-256 | 12267b7ea7136639b934b6a3365e76e38ed6143696c7bda299bd925f9b68ecb0 |
Hashes for mjml_python-1.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4fdf046bdfc7026974542be4ef6d17a5c927101d12f73a509ce02b4b087080a |
|
MD5 | e090397858cb55dfcc787ac5cfbe9331 |
|
BLAKE2b-256 | 7e1a3b8f5bf93a292a677cee934fc477dbdb389dfea434e00085ccfd791ca7b9 |
Hashes for mjml_python-1.2.1-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a5d4b01b657f5a4746f34fc193875229dca7587e9c1a4aaa8267701ca09554 |
|
MD5 | b2e2c01f268140cff4c09b240175c216 |
|
BLAKE2b-256 | 694b66b4138b35c8c6d06cc2b8111c171f1d237e2c2ab3e6ad7083f1a89ba207 |
Hashes for mjml_python-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee1203ba54dec32c06ea1b696342ba9dc8488215e246dc4b15c1858a9c7f5c4a |
|
MD5 | 2a097390f99ed0f00453e288a099925f |
|
BLAKE2b-256 | 57ab8ca141c8dbc8f46266c3e28c178c70154b18c041fae828dc007b401a0c42 |
Hashes for mjml_python-1.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d353ac5fd67e3f558c2d0967c1ee1ab74ab7373f10a47bb361ee05cc8923edc6 |
|
MD5 | 5f9a253757c0fe399c7614a29ff0c268 |
|
BLAKE2b-256 | aeccb94d7fc52c7f6951f0dedcf73f621beb8857b5a8de3338497cf96bb7e2f4 |
Hashes for mjml_python-1.2.1-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7ffe73bfccc4ece47392070dd73f3d61139ac979623b3f5308daa6cf8e98d44 |
|
MD5 | a9ebfa93f578353210c526190cbd5a9f |
|
BLAKE2b-256 | 16e358b806c883bf9b0b3a7364b1cfe8338cc26a558e6f47f75b419a69309baa |
Hashes for mjml_python-1.2.1-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aac4511a2756d4b438a90b089e313ff56a49e5e0f5444743a48ff50bcd7ee660 |
|
MD5 | 02a1da3bcf3bbb826c489dd3402f8d14 |
|
BLAKE2b-256 | f3c71277975f88b7542ee42b8d7a4dbd25bc7f1f63665e72faf4161870c66302 |
Hashes for mjml_python-1.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f747ac08d35b425120e5ca3cc5eb808f0f219c4e6519506588ff33608fc9c252 |
|
MD5 | 758ad3962dfb0a1bef8f1eba407c833f |
|
BLAKE2b-256 | bc4194225e16a549152d3fab421c3df36c75bb2dd9578984b551bdb515438883 |
Hashes for mjml_python-1.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8103c2902d1af685921bca5d512c0b41adfeb4a778bde3c8e9f444d81b23c99d |
|
MD5 | efe204a4e2ef5545b019e7859dc480fb |
|
BLAKE2b-256 | 5cbb8bf880fc37cccb403af62d394108ea7ae041284f2fe9e00a16792ccc907f |
Hashes for mjml_python-1.2.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32feb993f3818e9536637d6bf94ee7c040e609e75956829fdd74387be33be1a0 |
|
MD5 | 346fe968fc2d2227b496bff7b486fae5 |
|
BLAKE2b-256 | 23330d65399447f370089e7d2902ed06a43f6e4e1c111328428bc617a68b8a3f |
Hashes for mjml_python-1.2.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1e6014f948952826b27c7ad18b4c673d9e72ded330b1fe0f9910d53f7a2925e |
|
MD5 | 7543333df8c23070d09213f78aca7c0f |
|
BLAKE2b-256 | 61aaffdd976680b0bd7c87b0c4edad62b4d00fade9db4f595f83397215e2b0b4 |
Hashes for mjml_python-1.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a4fb8f4f08a38e3184922aa2ac2a577a859fde044b050e573f39054228150cf |
|
MD5 | eb33e46fe2a6aa5c5860f17c7c4aa547 |
|
BLAKE2b-256 | d880cad139ac8ac186068cbe3e6c70f569442a1e1c13c8f35ae3d47aa74620b4 |
Hashes for mjml_python-1.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 550d70ffe1afe9e1cee6c1c8246aa7bea885f2911454ae9b158781734e2627fd |
|
MD5 | 1d2249f70f5d95f7054f37d6bced84ad |
|
BLAKE2b-256 | 741b4bb7f8d24dc1d126eabcc43ebdc70332b66da9edbd3a9158bf06332a93b4 |
Hashes for mjml_python-1.2.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b3ca4a28a4e4d6b3588c53e3881d75ed8c3b8da42215b537b8f21028410872d |
|
MD5 | 8b391c820e7b92b09b273bdbc00a8cc0 |
|
BLAKE2b-256 | 4adc3770ee3709b205afe454ef199474e9208f1386897d48b3b8efb5efc13a1a |
Hashes for mjml_python-1.2.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e334c526d49faea384fe252b2fe751512a4670f8d983915ea0ed1d35d3beb5e |
|
MD5 | 66c0a9f071e4316beffaa2b280b1a30c |
|
BLAKE2b-256 | dfae55972cfadbb52a56d85dc6654cf42ae0c65d9a3dd0260729eb9a1f68b691 |
Hashes for mjml_python-1.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4364ad0043a9e72bad9612dd1be619ce8a1c87e488f696f814d69554f45e574 |
|
MD5 | 637e012bc1090f58bc0c40c32e0f5db2 |
|
BLAKE2b-256 | 346acb1068d3092b377d1c4c19981b2b18268c13e12ed6202a8c75ababd36bac |
Hashes for mjml_python-1.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b337d6942e924fb75f16e38c53677a45671db136c5b1f3aca0ff75c0b332be8d |
|
MD5 | 991c982e82a6013f1ea6e177bd6997df |
|
BLAKE2b-256 | 1ef7ff4e3942cd0a730f5766a3400bceaf9480639101159a4d3dc8f7c2860d84 |
Hashes for mjml_python-1.2.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | becc081b997c340a85a5369ba6d034b8092177c39356b3a4007c8583c5e12469 |
|
MD5 | a929f04170158d48af878458c969ebb3 |
|
BLAKE2b-256 | 33653eaba12c500fb3d15212f9e1aa22def0c16fbaa1baff9f53e2fba1d016fe |
Hashes for mjml_python-1.2.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1624899b9e34dddc797d7b4b04f113b05cf18753be6eabc6ee68e4dfa651174 |
|
MD5 | 10d1ad422d0c704640e20cde303de69a |
|
BLAKE2b-256 | ed442b3fd592fba2c55e65706a74c6bda1652c3fd7b8aeed1b3ce2204e40eafb |
Hashes for mjml_python-1.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6742f4e49bd02ade0d9e0e4b5821288a6095dc73bdbd71afc933cba78de4bbfc |
|
MD5 | 45a453b63bb1387621e9faae08713874 |
|
BLAKE2b-256 | 6954ef1bcb2bd371d133fd1f8aa20d8e56212a58faa13e476183f541ed1b9b15 |
Hashes for mjml_python-1.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39ece8ca9775dfdb4d15f4bb34b6389f83b6fc29c662f8af539ec1f5405ece31 |
|
MD5 | 6bad85d66ea53929904f0364414e5ea9 |
|
BLAKE2b-256 | 9bad9842cd62c34a27e6f692a6456111b1a7c8b6d40ec32106e02960b573e1c2 |
Hashes for mjml_python-1.2.1-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8e1bb3b415a1a7598dfe48fd4a62d437261a59c659cff17b55f0ca58123456b |
|
MD5 | 89989c8239a6778bf6eea097cad13306 |
|
BLAKE2b-256 | e4faab6c25481fb345e5c2c19969f50fb63eea8f0cf7f9890754c6bd9b73de3a |