mjml-python 1.4.0__tar.gz

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.
@@ -0,0 +1,14 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
14
+ - 'https://www.buymeacoffee.com/mgd020'
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Run code '...'
16
+ 2. See error
17
+
18
+ **Expected behavior**
19
+ A clear and concise description of what you expected to happen.
20
+
21
+ **Environment (please complete the following information):**
22
+ - OS: [e.g. MacOS]
23
+ - Arch: [e.g. x64, arm64]
24
+ - Python version [e.g. 3.10]
25
+ - Version [e.g. 1.0.0]
26
+
27
+ **Additional context**
28
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,154 @@
1
+ name: CI
2
+ permissions:
3
+ contents: read
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ pull_request:
8
+ release:
9
+ types: [published, released]
10
+
11
+ jobs:
12
+ tests:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v5
16
+ - name: Run tests
17
+ run: |
18
+ set -euo pipefail
19
+ python3 -m venv env
20
+ source env/bin/activate
21
+ pip install -r requirements.txt
22
+ maturin develop
23
+ python -m unittest
24
+
25
+ linux:
26
+ needs: [ tests ]
27
+ strategy:
28
+ fail-fast: true
29
+ matrix:
30
+ platform:
31
+ - target: x86_64
32
+ manylinux: auto
33
+ - target: aarch64
34
+ manylinux: auto
35
+ - target: x86_64-unknown-linux-musl
36
+ manylinux: musllinux_1_2
37
+ container: quay.io/pypa/musllinux_1_2_x86_64
38
+ - target: aarch64-unknown-linux-musl
39
+ manylinux: musllinux_1_2
40
+ runs-on: ubuntu-latest
41
+ steps:
42
+ - uses: actions/checkout@v5
43
+ - name: Build wheels
44
+ uses: PyO3/maturin-action@v1
45
+ with:
46
+ command: build
47
+ rust-toolchain: stable
48
+ manylinux: ${{ matrix.platform.manylinux }}
49
+ target: ${{ matrix.platform.target }}
50
+ container: ${{ matrix.platform.container }}
51
+ args: --release -o dist --find-interpreter
52
+ - name: Upload wheels
53
+ uses: actions/upload-artifact@v6
54
+ with:
55
+ name: wheel-linux-${{ matrix.platform.target }}
56
+ path: dist/*
57
+ retention-days: 1
58
+
59
+ windows:
60
+ needs: [ tests ]
61
+ runs-on: windows-latest
62
+ steps:
63
+ - uses: actions/checkout@v5
64
+ - name: Build wheels
65
+ uses: PyO3/maturin-action@v1
66
+ with:
67
+ command: build
68
+ rust-toolchain: stable
69
+ args: --release -o dist --find-interpreter
70
+ - name: Upload wheels
71
+ uses: actions/upload-artifact@v6
72
+ with:
73
+ name: wheel-windows
74
+ path: dist/*
75
+ retention-days: 1
76
+
77
+ macos:
78
+ needs: [ tests ]
79
+ strategy:
80
+ fail-fast: true
81
+ matrix:
82
+ target:
83
+ - aarch64-apple-darwin
84
+ - x86_64-apple-darwin
85
+ runs-on: macos-latest
86
+ steps:
87
+ - uses: actions/checkout@v5
88
+ - name: Build wheels
89
+ uses: PyO3/maturin-action@v1
90
+ with:
91
+ command: build
92
+ rust-toolchain: stable
93
+ args: --release -o dist --find-interpreter --target ${{ matrix.target }}
94
+ - name: Upload wheels
95
+ uses: actions/upload-artifact@v6
96
+ with:
97
+ name: wheel-macos-${{ matrix.target }}
98
+ path: dist/*
99
+ retention-days: 1
100
+
101
+ sdist:
102
+ needs: [ tests ]
103
+ runs-on: ubuntu-latest
104
+ steps:
105
+ - uses: actions/checkout@v5
106
+ - name: Build source distribution
107
+ uses: PyO3/maturin-action@v1
108
+ with:
109
+ command: sdist
110
+ rust-toolchain: stable
111
+ args: -o dist
112
+ - name: Upload source distribution
113
+ uses: actions/upload-artifact@v6
114
+ with:
115
+ name: sdist
116
+ path: dist/*
117
+ retention-days: 1
118
+
119
+ publish_testpypi:
120
+ name: Publish to test.pypi.org
121
+ runs-on: ubuntu-latest
122
+ if: >
123
+ github.event_name == 'release' && github.event.action == 'published' && github.event.release.prerelease == true
124
+ needs: [ macos, windows, linux, sdist ]
125
+ permissions:
126
+ id-token: write
127
+ environment: testpypi
128
+ steps:
129
+ - uses: actions/download-artifact@v7
130
+ with:
131
+ path: dist
132
+ merge-multiple: true
133
+ - uses: pypa/gh-action-pypi-publish@release/v1
134
+ with:
135
+ repository-url: https://test.pypi.org/legacy/
136
+ skip_existing: true
137
+
138
+ publish_pypi:
139
+ name: Publish to pypi.org
140
+ runs-on: ubuntu-latest
141
+ if: >
142
+ github.event_name == 'release' &&
143
+ (github.event.action == 'published' || github.event.action == 'released') &&
144
+ github.event.release.prerelease == false
145
+ needs: [ macos, windows, linux, sdist ]
146
+ permissions:
147
+ id-token: write
148
+ environment: pypi
149
+ steps:
150
+ - uses: actions/download-artifact@v7
151
+ with:
152
+ path: dist
153
+ merge-multiple: true
154
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,3 @@
1
+ /target
2
+ /env/
3
+ /.env*
@@ -0,0 +1,5 @@
1
+ # Contributing
2
+
3
+ PRs are welcome, but must be justified.
4
+
5
+ All PRs should ideally be linked to an issue. The issue is the place to discuss if any changes are justified.
@@ -0,0 +1,295 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "either"
7
+ version = "1.15.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
10
+
11
+ [[package]]
12
+ name = "enum-as-inner"
13
+ version = "0.6.1"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc"
16
+ dependencies = [
17
+ "heck",
18
+ "proc-macro2",
19
+ "quote",
20
+ "syn",
21
+ ]
22
+
23
+ [[package]]
24
+ name = "enum_dispatch"
25
+ version = "0.3.13"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd"
28
+ dependencies = [
29
+ "once_cell",
30
+ "proc-macro2",
31
+ "quote",
32
+ "syn",
33
+ ]
34
+
35
+ [[package]]
36
+ name = "equivalent"
37
+ version = "1.0.2"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
40
+
41
+ [[package]]
42
+ name = "hashbrown"
43
+ version = "0.15.2"
44
+ source = "registry+https://github.com/rust-lang/crates.io-index"
45
+ checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
46
+
47
+ [[package]]
48
+ name = "heck"
49
+ version = "0.5.0"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
52
+
53
+ [[package]]
54
+ name = "htmlparser"
55
+ version = "0.2.1"
56
+ source = "registry+https://github.com/rust-lang/crates.io-index"
57
+ checksum = "48ce8546b993eaf241d69ded33b1be6d205dd9857ec879d9d18bd05d3676e144"
58
+
59
+ [[package]]
60
+ name = "indexmap"
61
+ version = "2.8.0"
62
+ source = "registry+https://github.com/rust-lang/crates.io-index"
63
+ checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058"
64
+ dependencies = [
65
+ "equivalent",
66
+ "hashbrown",
67
+ "serde",
68
+ ]
69
+
70
+ [[package]]
71
+ name = "itertools"
72
+ version = "0.13.0"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
75
+ dependencies = [
76
+ "either",
77
+ ]
78
+
79
+ [[package]]
80
+ name = "itoa"
81
+ version = "1.0.15"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
84
+
85
+ [[package]]
86
+ name = "libc"
87
+ version = "0.2.171"
88
+ source = "registry+https://github.com/rust-lang/crates.io-index"
89
+ checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
90
+
91
+ [[package]]
92
+ name = "memchr"
93
+ version = "2.7.4"
94
+ source = "registry+https://github.com/rust-lang/crates.io-index"
95
+ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
96
+
97
+ [[package]]
98
+ name = "mjml-python"
99
+ version = "1.4.0"
100
+ dependencies = [
101
+ "mrml",
102
+ "pyo3",
103
+ ]
104
+
105
+ [[package]]
106
+ name = "mrml"
107
+ version = "5.0.0"
108
+ source = "registry+https://github.com/rust-lang/crates.io-index"
109
+ checksum = "9daf3c183141de1d3d2db6f275536c70ebfb87b11ed4b0c709b1103d1c9d3ede"
110
+ dependencies = [
111
+ "enum-as-inner",
112
+ "enum_dispatch",
113
+ "htmlparser",
114
+ "indexmap",
115
+ "itertools",
116
+ "rustc-hash",
117
+ "serde",
118
+ "serde_json",
119
+ "thiserror",
120
+ ]
121
+
122
+ [[package]]
123
+ name = "once_cell"
124
+ version = "1.21.1"
125
+ source = "registry+https://github.com/rust-lang/crates.io-index"
126
+ checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc"
127
+
128
+ [[package]]
129
+ name = "portable-atomic"
130
+ version = "1.11.0"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
133
+
134
+ [[package]]
135
+ name = "proc-macro2"
136
+ version = "1.0.94"
137
+ source = "registry+https://github.com/rust-lang/crates.io-index"
138
+ checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
139
+ dependencies = [
140
+ "unicode-ident",
141
+ ]
142
+
143
+ [[package]]
144
+ name = "pyo3"
145
+ version = "0.28.2"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "cf85e27e86080aafd5a22eae58a162e133a589551542b3e5cee4beb27e54f8e1"
148
+ dependencies = [
149
+ "libc",
150
+ "once_cell",
151
+ "portable-atomic",
152
+ "pyo3-build-config",
153
+ "pyo3-ffi",
154
+ "pyo3-macros",
155
+ ]
156
+
157
+ [[package]]
158
+ name = "pyo3-build-config"
159
+ version = "0.28.2"
160
+ source = "registry+https://github.com/rust-lang/crates.io-index"
161
+ checksum = "8bf94ee265674bf76c09fa430b0e99c26e319c945d96ca0d5a8215f31bf81cf7"
162
+ dependencies = [
163
+ "target-lexicon",
164
+ ]
165
+
166
+ [[package]]
167
+ name = "pyo3-ffi"
168
+ version = "0.28.2"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ checksum = "491aa5fc66d8059dd44a75f4580a2962c1862a1c2945359db36f6c2818b748dc"
171
+ dependencies = [
172
+ "libc",
173
+ "pyo3-build-config",
174
+ ]
175
+
176
+ [[package]]
177
+ name = "pyo3-macros"
178
+ version = "0.28.2"
179
+ source = "registry+https://github.com/rust-lang/crates.io-index"
180
+ checksum = "f5d671734e9d7a43449f8480f8b38115df67bef8d21f76837fa75ee7aaa5e52e"
181
+ dependencies = [
182
+ "proc-macro2",
183
+ "pyo3-macros-backend",
184
+ "quote",
185
+ "syn",
186
+ ]
187
+
188
+ [[package]]
189
+ name = "pyo3-macros-backend"
190
+ version = "0.28.2"
191
+ source = "registry+https://github.com/rust-lang/crates.io-index"
192
+ checksum = "22faaa1ce6c430a1f71658760497291065e6450d7b5dc2bcf254d49f66ee700a"
193
+ dependencies = [
194
+ "heck",
195
+ "proc-macro2",
196
+ "pyo3-build-config",
197
+ "quote",
198
+ "syn",
199
+ ]
200
+
201
+ [[package]]
202
+ name = "quote"
203
+ version = "1.0.40"
204
+ source = "registry+https://github.com/rust-lang/crates.io-index"
205
+ checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
206
+ dependencies = [
207
+ "proc-macro2",
208
+ ]
209
+
210
+ [[package]]
211
+ name = "rustc-hash"
212
+ version = "2.1.1"
213
+ source = "registry+https://github.com/rust-lang/crates.io-index"
214
+ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
215
+
216
+ [[package]]
217
+ name = "ryu"
218
+ version = "1.0.20"
219
+ source = "registry+https://github.com/rust-lang/crates.io-index"
220
+ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
221
+
222
+ [[package]]
223
+ name = "serde"
224
+ version = "1.0.219"
225
+ source = "registry+https://github.com/rust-lang/crates.io-index"
226
+ checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
227
+ dependencies = [
228
+ "serde_derive",
229
+ ]
230
+
231
+ [[package]]
232
+ name = "serde_derive"
233
+ version = "1.0.219"
234
+ source = "registry+https://github.com/rust-lang/crates.io-index"
235
+ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
236
+ dependencies = [
237
+ "proc-macro2",
238
+ "quote",
239
+ "syn",
240
+ ]
241
+
242
+ [[package]]
243
+ name = "serde_json"
244
+ version = "1.0.140"
245
+ source = "registry+https://github.com/rust-lang/crates.io-index"
246
+ checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
247
+ dependencies = [
248
+ "itoa",
249
+ "memchr",
250
+ "ryu",
251
+ "serde",
252
+ ]
253
+
254
+ [[package]]
255
+ name = "syn"
256
+ version = "2.0.100"
257
+ source = "registry+https://github.com/rust-lang/crates.io-index"
258
+ checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
259
+ dependencies = [
260
+ "proc-macro2",
261
+ "quote",
262
+ "unicode-ident",
263
+ ]
264
+
265
+ [[package]]
266
+ name = "target-lexicon"
267
+ version = "0.13.3"
268
+ source = "registry+https://github.com/rust-lang/crates.io-index"
269
+ checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c"
270
+
271
+ [[package]]
272
+ name = "thiserror"
273
+ version = "1.0.69"
274
+ source = "registry+https://github.com/rust-lang/crates.io-index"
275
+ checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
276
+ dependencies = [
277
+ "thiserror-impl",
278
+ ]
279
+
280
+ [[package]]
281
+ name = "thiserror-impl"
282
+ version = "1.0.69"
283
+ source = "registry+https://github.com/rust-lang/crates.io-index"
284
+ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
285
+ dependencies = [
286
+ "proc-macro2",
287
+ "quote",
288
+ "syn",
289
+ ]
290
+
291
+ [[package]]
292
+ name = "unicode-ident"
293
+ version = "1.0.18"
294
+ source = "registry+https://github.com/rust-lang/crates.io-index"
295
+ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "mjml-python"
3
+ version = "1.4.0"
4
+ edition = "2021"
5
+ readme = "README.md"
6
+
7
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+ [lib]
9
+ name = "mjml"
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies]
13
+ mrml = "5.0.0"
14
+ pyo3 = { version = "0.28.2", features = ["abi3-py38", "extension-module"] }
@@ -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.
@@ -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,150 @@
1
+ # `mjml-python`
2
+
3
+ Compile MJML at runtime **without** a Node.js service, external API, or subprocess.
4
+ `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).
5
+
6
+ ## Why
7
+
8
+ Using MJML traditionally requires either:
9
+
10
+ - running the Node.js-based MJML CLI as a subprocess, or
11
+ - calling an external MJML API service.
12
+
13
+ Both approaches add memory overhead, latency, operational complexity, and cost.
14
+
15
+ From [MRML](https://github.com/jolimail/mrml#why):
16
+
17
+ > 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.
18
+
19
+ By embedding the Rust engine directly, `mjml-python` avoids all external dependencies while retaining full MJML compatibility.
20
+
21
+ ## Installation
22
+
23
+ Install from [PyPI](https://pypi.org/project/mjml-python/):
24
+
25
+ ```sh
26
+ pip install mjml-python
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Call `mjml2html()` with your MJML string:
32
+
33
+ ```py
34
+ from mjml import mjml2html
35
+
36
+ html = mjml2html(
37
+ '''
38
+ <mjml>
39
+ <mj-body>
40
+ <mj-section>
41
+ <mj-column>
42
+ <mj-image width="100px" src="/assets/img/logo-small.png"></mj-image>
43
+ <mj-divider border-color="#F45E43"></mj-divider>
44
+ <!-- Say hello to the user -->
45
+ <mj-text font-size="20px" color="#F45E43" font-family="Open Sans">Hello World</mj-text>
46
+ </mj-column>
47
+ </mj-section>
48
+ <mj-section>
49
+ <mj-column>
50
+ <mj-social font-size="15px" icon-size="30px" mode="horizontal">
51
+ <mj-social-element name="facebook" href="https://mjml.io/">
52
+ Facebook
53
+ </mj-social-element>
54
+ <mj-social-element name="google" href="https://mjml.io/">
55
+ Google
56
+ </mj-social-element>
57
+ <mj-social-element name="twitter" href="https://mjml.io/">
58
+ Twitter
59
+ </mj-social-element>
60
+ </mj-social>
61
+ </mj-column>
62
+ </mj-section>
63
+ </mj-body>
64
+ </mjml>
65
+ ''',
66
+ disable_comments=True,
67
+ social_icon_origin="https://example.com",
68
+ fonts={
69
+ "Open Sans": "https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700",
70
+ "Ubuntu": "https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700",
71
+ }
72
+ )
73
+ ```
74
+
75
+ **Example using Django templates**
76
+
77
+ ```py
78
+ from django.core.mail import send_mail
79
+ from django.template.loader import render_to_string
80
+ from mjml import mjml2html
81
+
82
+ context = {'foo': 'bar'}
83
+ text_message = render_to_string('my_text_template.txt', context)
84
+ html_message = mjml2html(render_to_string('my_mjml_template.mjml', context))
85
+ send_mail(
86
+ 'Subject here',
87
+ text_message,
88
+ 'from@example.com',
89
+ ['to@example.com'],
90
+ fail_silently=False,
91
+ html_message=html_message,
92
+ )
93
+ ```
94
+
95
+ ## Configuration Options
96
+
97
+ `mjml-python` supports the following options:
98
+
99
+ | Name | Type | Default value | Comment |
100
+ |----------------------|--------------------------------|---------------|----------------------------------------------------------------------------------|
101
+ | `disable_comments` | `bool` | `False` | Strip comments out of rendered HTML |
102
+ | `social_icon_origin` | `str \| None` | `None` | Custom URL origin for social icons. Icon name is appended (e.g. `facebook.png`). |
103
+ | `fonts` | `dict[str, str] \| None` | `None` | Fonts imported in the HTML rendered by MJML. |
104
+ | `include_loader` | `Callable[[str], str] \| None` | `None` | Fetch the included template using the path attribute. |
105
+
106
+ **Default fonts** (used when `fonts=None`):
107
+
108
+ ```py
109
+ {
110
+ "Open Sans": "https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700",
111
+ "Droid Sans": "https://fonts.googleapis.com/css?family=Droid+Sans:300,400,500,700",
112
+ "Lato": "https://fonts.googleapis.com/css?family=Lato:300,400,500,700",
113
+ "Roboto": "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700",
114
+ "Ubuntu": "https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700",
115
+ }
116
+ ```
117
+
118
+ ## Why choose `mjml-python` instead of other MJML packages?
119
+
120
+ - **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.
121
+
122
+ - **Batteries-included defaults** – sensible defaults for fonts, comment handling, and include behavior, so most templates work with zero configuration.
123
+
124
+ - **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.
125
+
126
+ - **Minimal surface area** – intentionally focused on the common case: take MJML input → return production-ready HTML. No extra abstractions.
127
+
128
+ - **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.
129
+
130
+ - **Stable wheel builds** – lightweight ABI-3 wheels for all major platforms (CPython 3.7+), fast installation, and no compilation required on typical environments.
131
+
132
+ **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.
133
+
134
+ ## Development
135
+
136
+ With [Nix](https://nixos.org/):
137
+
138
+ ```sh
139
+ nix-shell
140
+ ```
141
+
142
+ With Python 3.7+, Rust and Cargo installed:
143
+
144
+ ```sh
145
+ python3 -m venv env
146
+ source env/bin/activate
147
+ pip install -r requirements.txt
148
+ maturin develop
149
+ python -m unittest
150
+ ```
@@ -0,0 +1,9 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Only the latest version will receive security updates.
6
+
7
+ ## Reporting a Vulnerability
8
+
9
+ Open an issue on GitHub.
@@ -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
+ """
@@ -0,0 +1,21 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.8.3,<2"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "mjml-python"
7
+ description = "A Python wrapper for MRML (Rust port of MJML)."
8
+ dynamic = ["version"]
9
+ readme = "README.md"
10
+ license = {file = "LICENSE"}
11
+ requires-python = ">=3.8"
12
+ classifiers = [
13
+ "Programming Language :: Rust",
14
+ "Programming Language :: Python :: Implementation :: CPython",
15
+ "Programming Language :: Python :: Implementation :: PyPy",
16
+ "License :: OSI Approved :: MIT License",
17
+ ]
18
+
19
+ [project.urls]
20
+ "Homepage" = "https://github.com/mgd020/mjml-python"
21
+ "Bug Tracker" = "https://github.com/mgd020/mjml-python/issues"
@@ -0,0 +1 @@
1
+ maturin>=1.8.3,<2
@@ -0,0 +1,17 @@
1
+ { pkgs ? import <nixpkgs> {} }:
2
+
3
+ pkgs.mkShell {
4
+ nativeBuildInputs = with pkgs.buildPackages; [
5
+ # https://search.nixos.org/packages
6
+ python3
7
+ rustc
8
+ cargo
9
+ ] ++ lib.optional stdenv.isDarwin libiconv;
10
+ shellHook = ''
11
+ export VIRTUAL_ENV_DISABLE_PROMPT=1
12
+ python3 -m venv .env
13
+ . .env/bin/activate
14
+ pip install -r requirements.txt
15
+ maturin develop
16
+ '';
17
+ }
@@ -0,0 +1,64 @@
1
+ use mrml;
2
+ use mrml::prelude::parser::loader::*;
3
+ use mrml::prelude::parser::*;
4
+ use mrml::prelude::render::*;
5
+ use pyo3::exceptions::PyValueError;
6
+ use pyo3::prelude::*;
7
+ use std::borrow::Cow;
8
+ use std::collections::HashMap;
9
+ use std::io::ErrorKind;
10
+
11
+ #[derive(Debug)]
12
+ struct CallbackIncludeLoader(pub Py<PyAny>);
13
+
14
+ impl IncludeLoader for CallbackIncludeLoader {
15
+ fn resolve(&self, path: &str) -> Result<String, IncludeLoaderError> {
16
+ Python::attach(|py| {
17
+ self.0
18
+ .call1(py, (path,))
19
+ .and_then(|o| o.extract::<String>(py))
20
+ .map_err(|_| IncludeLoaderError::new(path, ErrorKind::Other))
21
+ })
22
+ }
23
+ }
24
+
25
+ #[pyfunction]
26
+ #[pyo3(signature = (input, *, disable_comments=false, social_icon_origin=None, fonts=None, include_loader=None))]
27
+ fn mjml2html(
28
+ input: String,
29
+ disable_comments: bool,
30
+ social_icon_origin: Option<String>,
31
+ fonts: Option<HashMap<String, String>>,
32
+ include_loader: Option<Py<PyAny>>,
33
+ ) -> PyResult<String> {
34
+ let parse_opts = ParserOptions {
35
+ include_loader: match include_loader {
36
+ None => Box::new(noop_loader::NoopIncludeLoader),
37
+ Some(item) => Box::new(CallbackIncludeLoader(item)),
38
+ },
39
+ };
40
+
41
+ let root = mrml::parse_with_options(input, &parse_opts)
42
+ .map_err(|e| PyValueError::new_err(e.to_string()))?;
43
+
44
+ let fonts_map = match fonts {
45
+ None => RenderOptions::default().fonts,
46
+ Some(item) => item.into_iter().map(|(k, v)| (k, Cow::Owned(v))).collect(),
47
+ };
48
+
49
+ let render_opts = RenderOptions {
50
+ disable_comments,
51
+ social_icon_origin: social_icon_origin.map(Into::into),
52
+ fonts: fonts_map,
53
+ };
54
+
55
+ root.element
56
+ .render(&render_opts)
57
+ .map_err(|e| PyValueError::new_err(e.to_string()))
58
+ }
59
+
60
+ #[pymodule]
61
+ fn mjml(_py: Python<'_>, m: &Bound<PyModule>) -> PyResult<()> {
62
+ m.add_function(wrap_pyfunction!(mjml2html, m)?)?;
63
+ Ok(())
64
+ }
File without changes
@@ -0,0 +1,173 @@
1
+ import unittest
2
+ from mjml import mjml2html
3
+
4
+
5
+ class TestSimple(unittest.TestCase):
6
+ def test_good(self):
7
+ result = mjml2html(
8
+ """
9
+ <mjml><mj-body><mj-section><mj-column>
10
+ <mj-text>Hello World</mj-text>
11
+ </mj-column></mj-section></mj-body></mjml>
12
+ """
13
+ )
14
+ self.assertRegex(result, r"^<!doctype html>")
15
+ self.assertRegex(result, r">Hello World<")
16
+
17
+ def test_bad(self):
18
+ with self.assertRaises(ValueError) as ctx:
19
+ mjml2html("""<mj-text>Hello World</mj-text>""")
20
+ self.assertIn("unexpected token", str(ctx.exception))
21
+
22
+
23
+ class TestDisableComments(unittest.TestCase):
24
+ string = """
25
+ <mjml><mj-body><mj-section><mj-column>
26
+ <!-- this is a comment -->
27
+ <mj-text>Hello World</mj-text>
28
+ </mj-column></mj-section></mj-body></mjml>
29
+ """
30
+
31
+ def test_false(self):
32
+ result = mjml2html(self.string, disable_comments=False)
33
+ self.assertIn("<!-- this is a comment -->", result)
34
+
35
+ def test_true(self):
36
+ result = mjml2html(self.string, disable_comments=True)
37
+ self.assertNotIn("<!-- this is a comment -->", result)
38
+
39
+
40
+ class TestSocialIconOrigin(unittest.TestCase):
41
+ string = """
42
+ <mjml><mj-body><mj-section><mj-column>
43
+ <mj-social><mj-social-element name="facebook" href="https://example.invalid/"/></mj-social>
44
+ </mj-column></mj-section></mj-body></mjml>
45
+ """
46
+
47
+ def test_default(self):
48
+ result = mjml2html(self.string, social_icon_origin=None)
49
+ self.assertIn(
50
+ 'href="https://www.facebook.com/sharer/sharer.php?u=https://example.invalid/"',
51
+ result,
52
+ )
53
+ self.assertIn(
54
+ 'src="https://www.mailjet.com/images/theme/v1/icons/ico-social/facebook.png"',
55
+ result,
56
+ )
57
+
58
+ def test_override(self):
59
+ result = mjml2html(self.string, social_icon_origin="https://example.invalid/")
60
+ self.assertIn(
61
+ 'href="https://www.facebook.com/sharer/sharer.php?u=https://example.invalid/"',
62
+ result,
63
+ )
64
+ self.assertIn('src="https://example.invalid/facebook.png"', result)
65
+
66
+
67
+ class TestFonts(unittest.TestCase):
68
+ string = """
69
+ <mjml><mj-body><mj-section><mj-column>
70
+ <mj-text font-family="Honk">Honk</mj-text>
71
+ <mj-text font-family="Open Sans">Open Sans</mj-text>
72
+ <mj-text font-family="Missing">Missing</mj-text>
73
+ </mj-column></mj-section></mj-body></mjml>
74
+ """
75
+
76
+ def test_default(self):
77
+ result = mjml2html(self.string, fonts=None)
78
+ self.assertNotIn("https://example.com/fonts?family=Honk", result)
79
+ self.assertIn("https://fonts.googleapis.com/css?family=Open+Sans", result)
80
+
81
+ def test_override(self):
82
+ result = mjml2html(
83
+ self.string,
84
+ fonts={
85
+ "Honk": "https://example.com/fonts?family=Honk",
86
+ "Open Sans": "https://example.com/fonts?family=Open+Sans",
87
+ },
88
+ )
89
+ self.assertIn("https://example.com/fonts?family=Honk", result)
90
+ self.assertIn("https://example.com/fonts?family=Open+Sans", result)
91
+
92
+ def test_head_override(self):
93
+ result = mjml2html(
94
+ self.string.replace(
95
+ "<mjml>",
96
+ """
97
+ <mjml><mj-head>
98
+ <mj-font name="Honk" href="https://example.com/fonts?family=Honk"></mj-font>
99
+ <mj-font name="Open Sans" href="https://example.com/fonts?family=Open+Sans"></mj-font>
100
+ </mj-head>
101
+ """,
102
+ )
103
+ )
104
+ self.assertIn("https://example.com/fonts?family=Honk", result)
105
+ self.assertIn("https://example.com/fonts?family=Open+Sans", result)
106
+
107
+
108
+ class TestIncludeLoader(unittest.TestCase):
109
+ include_string = '<mj-include path="inner.mjml" />'
110
+
111
+ outer_string = f"""
112
+ <mjml>
113
+ <mj-head>
114
+ {include_string}
115
+ </mj-head>
116
+ <mj-body>
117
+ <mj-section>
118
+ <mj-column>
119
+ <mj-include path="text.mjml" />
120
+ </mj-column>
121
+ </mj-section>
122
+ </mj-body>
123
+ </mjml>
124
+ """
125
+
126
+ inner_string = """
127
+ <mj-attributes>
128
+ <mj-text padding="0" />
129
+ <mj-class name="blue" color="blue" />
130
+ <mj-class name="big" font-size="20px" />
131
+ <mj-all font-family="Arial" />
132
+ </mj-attributes>
133
+ """
134
+
135
+ text_string = """
136
+ <mj-text mj-class="blue big">Hello World</mj-text>
137
+ """
138
+
139
+ def test_ok(self):
140
+ strings = {"inner.mjml": self.inner_string, "text.mjml": self.text_string}
141
+ result = mjml2html(self.outer_string, include_loader=strings.__getitem__)
142
+ self.assertRegex(result, r"^<!doctype html>")
143
+ self.assertRegex(result, r">Hello World<")
144
+
145
+ def test_missing(self):
146
+ strings = {}
147
+ with self.assertRaises(ValueError) as ctx:
148
+ mjml2html(self.outer_string, include_loader=strings.__getitem__)
149
+ self.assertIn("unable to load included template", str(ctx.exception))
150
+
151
+ def test_head_attributes(self):
152
+ strings = {"inner.mjml": self.inner_string, "text.mjml": self.text_string}
153
+ result = mjml2html(self.outer_string, include_loader=strings.__getitem__)
154
+ expected = mjml2html(
155
+ self.outer_string.replace(self.include_string, self.inner_string),
156
+ include_loader=strings.__getitem__,
157
+ )
158
+ self.assertEqual(result, expected)
159
+
160
+ def test_include_css(self):
161
+ mjml = """
162
+ <mjml>
163
+ <mj-head>
164
+ <mj-include path="styles.css" type="css" />
165
+ </mj-head>
166
+ </mjml>
167
+ """
168
+ strings = {"styles.css": ".some-class { font-family: monospace }"}
169
+ result = mjml2html(mjml, include_loader=strings.__getitem__)
170
+ self.assertRegex(
171
+ result,
172
+ r"<style type=\"text/css\">.some-class { font-family: monospace }</style>",
173
+ )