Skip to main content

mjml-stub

This is an unofficial Python port of mjml v4. It is implemented in pure Python and does not require JavaScript/NodeJS. mjml is a markup language created by Mailjet and designed to reduce the pain of coding a responsive email.

pip install mjml

WARNING: stub implementation only!

This library only implements a subset of the original MJML project. It lacks several features found in the JavaScript mjml implementation (e.g. minification, beautification and validation). Also the code likely contains many additional bugs.

The upside is that there are lot of possibilities for you to make a real difference when you improve the code :-)

Goals / Motivation

This library should track the JS version of mjml so ideally you should get the same HTML. However even under the best circumstances this library will always lag a bit behind as each change must be translated to Python manually (a mostly mechanical process).

While I like the idea behind mjml and all the knowledge about the quirks to get acceptable HTML rendering by various email clients we did not want to deploy a Node.js-based stack on our production servers. We did not feel comfortable auditing all 220 JS packages which are installed by npm install mjml (and re-doing this whenever new versions are available). Also due to data-privacy concerns we were unable to use any third-party products (i.e. MJML's API offering).

After a short spike to check the viability of a Python implementation I went ahead and wrote enough code to ensure some existing messages could be converted to mjml. Currently the library is deployed in some light production scenarios.

Another benefit of using Python is that we can integrate that in our web apps more closely. As the startup overhead of CPython is much lower than Node.js we can also generate a few mails via CLI applications without massive performance problems. CPython uses ~70ms to translate a trivial mjml template to HTML while Node.JS needs ~650ms.

Documentation

The idea is to implement the mjml XML dialect exactly like the JS implementation so eventually you should be able to use the official docs and other online resources found on mjml.io. However we are nowhere near that right now! The current code can render the "Hello World" example as well as images, tables and groups but many components remain to be reimplemented. I'd love to see your pull requests to improve the current state though.

Alternatives / Additional Resources

  • django-mjml: If deploying NodeJS is not an issue and you are using Django you could use the well established django-mjml library. That library integrates the mjml JavaScript implementation with Django templates so you can access all mjml features.
  • MJML.NET: This is an unofficial port of mjml to C# (github repo which supports more components than this Python implementation.
  • email-bugs is a github project which contains a lot of knowledge about rendering quirks in various email clients.
  • htmlemailcheck is a commercial offering to help you checking email rendering in various environments. I don't have any experience with their services but they provide a free knowledgebase.

Metadata

Release files for mjml 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mjml 0.6.2
File Size Uploaded
mjml-0.6.2.tar.gz 36.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mjml 0.6.2
File Interpreter ABI Platform
mjml-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 77.1 kB

Release files / mjml-0.6.2.tar.gz

Download URL mjml-0.6.2.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f9e40e6d060c6aeceb0019e806199e99becc84e4fb4af2391456db8d97554d95
BLAKE2b-256 checksum
How to use checksums
6bb768f0915a1dab3e7ada9585199f52ff36d7848959cbef8c53dc4efc859851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Release files / mjml-0.6.2-py3-none-any.whl

Download URL mjml-0.6.2-py3-none-any.whl
Size 40.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1891f3151023c8edc59d60e574c94a1845836f3408b0ef8b8f68e84ec7d8048
BLAKE2b-256 checksum
How to use checksums
1fb8bb9e504f8c31f4d32b9a3cca55af35d3364a0e63826e0f9a5ef998d658d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

Release history Release notifications | RSS feed

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page