Skip to main content

MJML email builder

Project description

MJML Builder

This project is a python library used to build mjml markup in a programmatic way.

Table of contents

How to use

Building the email

There are two ways to build an email. The two examples below both result in the same output.

Using the builder

from mjml_builder import components as c
from mjml_builder import Builder

email_builder = (
    Builder()
    .add_content("Hello", font_size="20px", align="center")
    .add_column()
    .add_content("World", color="red")
    .add_section()
    .add_content(
        c.Accordion(
            c.AccordionElement("Title 1", "Content of the accordion 1"),
            c.AccordionElement("Title 2", "Content of the accordion 1"),
        )
    )
    .add_section()
    .add_content(c.Image("https://picsum.photos/200", width="200px"))
)
email = email_builder.build()

Using components directly

from mjml_builder import components as c

email = c.Body(
    c.Section(
        c.Column(
            c.Text(
                "Hello",
                align="center",
                font_size="20px",
            )
        ),
        c.Column(
            c.Text(
                "World",
                color="red",
            )
        ),
    ),
    c.Section(
        c.Column(
            c.Accordion(
                c.AccordionElement("Title 1", "Content of the accordion 1"),
                c.AccordionElement("Title 2", "Content of the accordion 1"),
            )
        )
    ),
    c.Section(c.Column(
        c.Image("https://picsum.photos/200", width="200px")
    )),
)

Generating markup

The email component built using the Builder().build() or using the components directly has properties that can be used to access various representations of the email.

Generate mjml markup

You can generate a mjml representation of the email using.

email.mjml

Generate html markup

You can generate a html representation of the email using.

email.html

To generate html one of the following must be true.

  • Have the mrml library installed using

    uv add mrml # or pip install mrml
    
  • Have the mjml cli available in path. This can be installed using

    npm i -g mjml # or bun,pnpm etc
    
  • Have one of bun, pnpm or npm installed. The html will then be generated using bunx mjml, pnpx mjml or npx mjml.

Generate text

You can generate a text representation of the email using.

email.text

Generate dict

You can generate a dict representation of the email using. This dict matches the format defined in the MJML Docs

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_builder-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mjml_builder-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file mjml_builder-0.1.0.tar.gz.

File metadata

  • Download URL: mjml_builder-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for mjml_builder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 597ef7d11bfb42a18969f0ab5d27d1ff6e81704473c61adf719b94c231bb3096
MD5 03d800e70940fac8b9a9352e41d18909
BLAKE2b-256 e5db93f853ba8575f18d7f9dd1e451bc0bff4de461e036928cb4305e31668b28

See more details on using hashes here.

File details

Details for the file mjml_builder-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mjml_builder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ade14a330b5b46640998b198ba8a81530cd3c1bf31995ef3a540930aba0f662
MD5 042f69c526cf69b837a78341f09ee303
BLAKE2b-256 f37857c93cb9912cc39e50ad0bd1321c4ab66dfb800c2fd3cbe1d0ffa9c96428

See more details on using hashes here.

Supported by

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