mjml-python 1.4.0__cp38-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mjml/__init__.py +5 -0
- mjml/__init__.pyi +27 -0
- mjml/mjml.pyd +0 -0
- mjml/py.typed +0 -0
- mjml_python-1.4.0.dist-info/METADATA +165 -0
- mjml_python-1.4.0.dist-info/RECORD +9 -0
- mjml_python-1.4.0.dist-info/WHEEL +4 -0
- mjml_python-1.4.0.dist-info/licenses/LICENSE +21 -0
- mjml_python-1.4.0.dist-info/sboms/mjml-python.cyclonedx.json +1222 -0
mjml/__init__.py
ADDED
mjml/__init__.pyi
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from typing import Optional, Dict, Protocol
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class IncludeLoader(Protocol):
|
|
5
|
+
def __call__(self, path: str) -> str: ...
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def mjml2html(
|
|
9
|
+
input: str,
|
|
10
|
+
*,
|
|
11
|
+
disable_comments: bool = False,
|
|
12
|
+
social_icon_origin: Optional[str] = None,
|
|
13
|
+
fonts: Optional[Dict[str, str]] = None,
|
|
14
|
+
include_loader: Optional[IncludeLoader] = None,
|
|
15
|
+
) -> str:
|
|
16
|
+
"""Convert MJML string to HTML string.
|
|
17
|
+
|
|
18
|
+
Params:
|
|
19
|
+
- input: The input MJML string
|
|
20
|
+
- disable_comments: Strip comments out of rendered HTML
|
|
21
|
+
- social_icon_origin: Custom URL origin for social icons. Icon name is appended
|
|
22
|
+
(e.g. `facebook.png`).
|
|
23
|
+
- fonts: Fonts imported in the HTML rendered by MJML.
|
|
24
|
+
- include_loader: Fetch the included template using the path attribute.
|
|
25
|
+
|
|
26
|
+
Returns: the rendered HTML string.
|
|
27
|
+
"""
|
mjml/mjml.pyd
ADDED
|
Binary file
|
mjml/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mjml-python
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Summary: A Python wrapper for MRML (Rust port of MJML).
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
12
|
+
Project-URL: Bug Tracker, https://github.com/mgd020/mjml-python/issues
|
|
13
|
+
Project-URL: Homepage, https://github.com/mgd020/mjml-python
|
|
14
|
+
|
|
15
|
+
# `mjml-python`
|
|
16
|
+
|
|
17
|
+
Compile MJML at runtime **without** a Node.js service, external API, or subprocess.
|
|
18
|
+
`mjml-python` is a Python wrapper around the Rust MJML engine [MRML](https://github.com/jdrouet/mrml), a high-performance port of the official [MJML](https://github.com/mjmlio/mjml).
|
|
19
|
+
|
|
20
|
+
## Why
|
|
21
|
+
|
|
22
|
+
Using MJML traditionally requires either:
|
|
23
|
+
|
|
24
|
+
- running the Node.js-based MJML CLI as a subprocess, or
|
|
25
|
+
- calling an external MJML API service.
|
|
26
|
+
|
|
27
|
+
Both approaches add memory overhead, latency, operational complexity, and cost.
|
|
28
|
+
|
|
29
|
+
From [MRML](https://github.com/jolimail/mrml#why):
|
|
30
|
+
|
|
31
|
+
> 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.
|
|
32
|
+
|
|
33
|
+
By embedding the Rust engine directly, `mjml-python` avoids all external dependencies while retaining full MJML compatibility.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
Install from [PyPI](https://pypi.org/project/mjml-python/):
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
pip install mjml-python
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
Call `mjml2html()` with your MJML string:
|
|
46
|
+
|
|
47
|
+
```py
|
|
48
|
+
from mjml import mjml2html
|
|
49
|
+
|
|
50
|
+
html = mjml2html(
|
|
51
|
+
'''
|
|
52
|
+
<mjml>
|
|
53
|
+
<mj-body>
|
|
54
|
+
<mj-section>
|
|
55
|
+
<mj-column>
|
|
56
|
+
<mj-image width="100px" src="/assets/img/logo-small.png"></mj-image>
|
|
57
|
+
<mj-divider border-color="#F45E43"></mj-divider>
|
|
58
|
+
<!-- Say hello to the user -->
|
|
59
|
+
<mj-text font-size="20px" color="#F45E43" font-family="Open Sans">Hello World</mj-text>
|
|
60
|
+
</mj-column>
|
|
61
|
+
</mj-section>
|
|
62
|
+
<mj-section>
|
|
63
|
+
<mj-column>
|
|
64
|
+
<mj-social font-size="15px" icon-size="30px" mode="horizontal">
|
|
65
|
+
<mj-social-element name="facebook" href="https://mjml.io/">
|
|
66
|
+
Facebook
|
|
67
|
+
</mj-social-element>
|
|
68
|
+
<mj-social-element name="google" href="https://mjml.io/">
|
|
69
|
+
Google
|
|
70
|
+
</mj-social-element>
|
|
71
|
+
<mj-social-element name="twitter" href="https://mjml.io/">
|
|
72
|
+
Twitter
|
|
73
|
+
</mj-social-element>
|
|
74
|
+
</mj-social>
|
|
75
|
+
</mj-column>
|
|
76
|
+
</mj-section>
|
|
77
|
+
</mj-body>
|
|
78
|
+
</mjml>
|
|
79
|
+
''',
|
|
80
|
+
disable_comments=True,
|
|
81
|
+
social_icon_origin="https://example.com",
|
|
82
|
+
fonts={
|
|
83
|
+
"Open Sans": "https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700",
|
|
84
|
+
"Ubuntu": "https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700",
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Example using Django templates**
|
|
90
|
+
|
|
91
|
+
```py
|
|
92
|
+
from django.core.mail import send_mail
|
|
93
|
+
from django.template.loader import render_to_string
|
|
94
|
+
from mjml import mjml2html
|
|
95
|
+
|
|
96
|
+
context = {'foo': 'bar'}
|
|
97
|
+
text_message = render_to_string('my_text_template.txt', context)
|
|
98
|
+
html_message = mjml2html(render_to_string('my_mjml_template.mjml', context))
|
|
99
|
+
send_mail(
|
|
100
|
+
'Subject here',
|
|
101
|
+
text_message,
|
|
102
|
+
'from@example.com',
|
|
103
|
+
['to@example.com'],
|
|
104
|
+
fail_silently=False,
|
|
105
|
+
html_message=html_message,
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Configuration Options
|
|
110
|
+
|
|
111
|
+
`mjml-python` supports the following options:
|
|
112
|
+
|
|
113
|
+
| Name | Type | Default value | Comment |
|
|
114
|
+
|----------------------|--------------------------------|---------------|----------------------------------------------------------------------------------|
|
|
115
|
+
| `disable_comments` | `bool` | `False` | Strip comments out of rendered HTML |
|
|
116
|
+
| `social_icon_origin` | `str \| None` | `None` | Custom URL origin for social icons. Icon name is appended (e.g. `facebook.png`). |
|
|
117
|
+
| `fonts` | `dict[str, str] \| None` | `None` | Fonts imported in the HTML rendered by MJML. |
|
|
118
|
+
| `include_loader` | `Callable[[str], str] \| None` | `None` | Fetch the included template using the path attribute. |
|
|
119
|
+
|
|
120
|
+
**Default fonts** (used when `fonts=None`):
|
|
121
|
+
|
|
122
|
+
```py
|
|
123
|
+
{
|
|
124
|
+
"Open Sans": "https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700",
|
|
125
|
+
"Droid Sans": "https://fonts.googleapis.com/css?family=Droid+Sans:300,400,500,700",
|
|
126
|
+
"Lato": "https://fonts.googleapis.com/css?family=Lato:300,400,500,700",
|
|
127
|
+
"Roboto": "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700",
|
|
128
|
+
"Ubuntu": "https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700",
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Why choose `mjml-python` instead of other MJML packages?
|
|
133
|
+
|
|
134
|
+
- **Simple, Pythonic API** – a single `mjml2html()` function that takes plain keyword arguments and returns a clean HTML string. No need to construct parser/render option objects or work with custom result classes.
|
|
135
|
+
|
|
136
|
+
- **Batteries-included defaults** – sensible defaults for fonts, comment handling, and include behavior, so most templates work with zero configuration.
|
|
137
|
+
|
|
138
|
+
- **Flexible include loader** – pass a Python callable to handle `<mj-include>` however you like (filesystem, database, HTTP, etc.) without learning MRML’s multiple loader types.
|
|
139
|
+
|
|
140
|
+
- **Minimal surface area** – intentionally focused on the common case: take MJML input → return production-ready HTML. No extra abstractions.
|
|
141
|
+
|
|
142
|
+
- **No external services or subprocesses required** – rendering is performed entirely inside the Python extension using the embedded Rust MJML engine. No Node.js installation, MJML CLI, or HTTP API needed.
|
|
143
|
+
|
|
144
|
+
- **Stable wheel builds** – lightweight ABI-3 wheels for all major platforms (CPython 3.7+), fast installation, and no compilation required on typical environments.
|
|
145
|
+
|
|
146
|
+
**In short:** `mjml-python` is ideal when you want a straightforward, Python-friendly way to render MJML without dealing with the full MRML configuration surface or external tooling.
|
|
147
|
+
|
|
148
|
+
## Development
|
|
149
|
+
|
|
150
|
+
With [Nix](https://nixos.org/):
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
nix-shell
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
With Python 3.7+, Rust and Cargo installed:
|
|
157
|
+
|
|
158
|
+
```sh
|
|
159
|
+
python3 -m venv env
|
|
160
|
+
source env/bin/activate
|
|
161
|
+
pip install -r requirements.txt
|
|
162
|
+
maturin develop
|
|
163
|
+
python -m unittest
|
|
164
|
+
```
|
|
165
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mjml/__init__.py,sha256=2dJmpc4qHjvXHjqcsnJ6bJgRlD9e7pB4Oqe6RoEzmLQ,99
|
|
2
|
+
mjml/__init__.pyi,sha256=-6SLESiNwxBIanERBO1zbJLbk6QC82PNFYiWn0E8njE,826
|
|
3
|
+
mjml/mjml.pyd,sha256=Mw5Y9Phzfu-mpmehTohkCf0JN57Ro2c27rCoNrp9Ylc,1270784
|
|
4
|
+
mjml/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
mjml_python-1.4.0.dist-info/METADATA,sha256=PVo0tZBsO4RrQ8CFVbyBxnpD0IWKiy9HzVsuaowknPU,6876
|
|
6
|
+
mjml_python-1.4.0.dist-info/WHEEL,sha256=X8vvqavrCCzME4tEQB46rFZlEGXF4kNwLeRqgaDmIw4,95
|
|
7
|
+
mjml_python-1.4.0.dist-info/licenses/LICENSE,sha256=Ogx1hV6q5PLAjCw0garKjEiH7GUmFydh4DuWyd5VOs4,1095
|
|
8
|
+
mjml_python-1.4.0.dist-info/sboms/mjml-python.cyclonedx.json,sha256=zJhBXXWuyVDF4BH1BLTMR4C3XRY5_V4p7206NSUGMFk,37669
|
|
9
|
+
mjml_python-1.4.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 github.com/mgd020
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|