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.1.tar.gz (6.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.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mjml_builder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aec9add4f7caf555123709dd195b88521c6d46cde262c3c009cbbe64cac2ba38
MD5 c6ba3fdbc3529caf2c565bcdcbbae53f
BLAKE2b-256 9f71ab9500cad2f73426da4917cd82f10551e1300cb6a20110b1a43d1bf3f134

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mjml_builder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b689bb14179adde3bae69225a376daebedfac3943178773c3d9f074a270ebdff
MD5 448ec04395a499c6f9d901ae2698c5f2
BLAKE2b-256 6419b3a501971d94d7fe597a079b3710f4c1a4e46c3a71ed4233e94a6c577c3e

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