Skip to main content

Python implementation for MJML - a framework that makes responsive-email easy

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mjml-0.7.0.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

mjml-0.7.0-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file mjml-0.7.0.tar.gz.

File metadata

  • Download URL: mjml-0.7.0.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.10.3

File hashes

Hashes for mjml-0.7.0.tar.gz
Algorithm Hash digest
SHA256 39d27297c08cb27909f2192b0cbb11a9e18b141ca9956e810cc78a39c923d34d
MD5 8eededaa2cedd86b5dd1b6d5ec4f7ac2
BLAKE2b-256 c4b6117f3774e8fbdca4bbe05dc1397242f431bf36f57cd14a62f0a8567253b6

See more details on using hashes here.

File details

Details for the file mjml-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: mjml-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.10.3

File hashes

Hashes for mjml-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6e81cd6412953a40f958e3347975b43a01411568c3063e9a3407cf1078b53d8
MD5 ea24e5eb2a943a5957f0354af381f2d1
BLAKE2b-256 d3e09a8da14408312dc0c3b08d5a5c9cab5c09652ca8644bd4cb201a4f55c531

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page