Fast CSS inlining written in Rust
Project description
css_inline
Blazing-fast CSS inlining for Python implemented with Mozilla's Servo project components.
Features:
- Removing
style
tags after inlining; - Resolving external stylesheets (including local files);
- Control if
style
tags should be processed; - Out-of-document CSS to inline;
- Inlining multiple documents in parallel (via Rust-level threads)
The project supports CSS Syntax Level 3.
Installation
To install css_inline
via pip
run the following command:
pip install css_inline
Pre-compiled wheels for most popular platforms are provided. If your platform is not in the support table below, you will need a Rust compiler to build this package from source. The minimum supported Rust version is 1.54.
Usage
To inline CSS in a HTML document:
import css_inline
HTML = """<html>
<head>
<title>Test</title>
<style>h1 { color:blue; }</style>
</head>
<body>
<h1>Big Text</h1>
</body>
</html>"""
inlined = css_inline.inline(HTML)
# HTML becomes this:
#
# <html>
# <head>
# <title>Test</title>
# <style>h1 { color:blue; }</style>
# </head>
# <body>
# <h1 style="color:blue;">Big Text</h1>
# </body>
# </html>
If you want to inline many HTML documents, you can utilize inline_many
that processes the input in parallel.
import css_inline
css_inline.inline_many(["<...>", "<...>"])
inline_many
will use Rust-level threads; thus, you can expect it's running faster than css_inline.inline
via Python's multiprocessing
or threading
modules.
For customization options use the CSSInliner
class:
import css_inline
inliner = css_inline.CSSInliner(remove_style_tags=True)
inliner.inline("...")
Performance
Due to the usage of efficient tooling from Mozilla's Servo project (html5ever
, rust-cssparser
and others) this
library has excellent performance characteristics. In comparison with other Python projects, it is ~7-15x faster than the nearest alternative.
For inlining CSS in the html document from the Usage
section above there is the following breakdown in the benchmarks:
css_inline 0.8.2
- 21.75 uspremailer 3.10.0
- 329.51 us (x15.14)toronado 0.1.0
- 1.59 ms (x73.28)inlinestyler 0.2.5
- 2.37 ms (x109.27)pynliner 0.8.0
- 2.78 ms (x127.89)
And for a more realistic email:
css_inline 0.8.2
- 443.83 uspremailer 3.10.0
- 3.25 ms (x7.33)toronado 0.1.0
- 35.35 ms (x79.65)inlinestyler 0.2.5
- 61.08 ms (x137.62)pynliner 0.8.0
- 99.52 ms (x224.24)
You can take a look at the benchmarks' code at benches/bench.py
file.
The results above were measured with stable rustc 1.61.0
, Python 3.10.4
, Linux x86_64
on i8700K, and 32GB RAM.
Python support
css_inline
supports CPython 3.7, 3.8, 3.9, 3.10, and PyPy 3.7 and 3.8.
The following wheels are available:
manylinux musllinux x86_64 |
macOS Intel | macOS ARM64 | Windows 64bit | Windows 32bit | |
---|---|---|---|---|---|
CPython 3.7 | ✔ | ✔️ | ✔ | ✔️ | ✔️ |
CPython 3.8 | ✔ | ✔️ | ✔️ | ✔️ | ✔️ |
CPython 3.9 | ✔ | ✔️ | ✔️ | ✔️ | ✔️ |
CPython 3.10 | ✔ | ✔️ | ✔️ | ✔️ | ✔️ |
PyPy 3.7 v7.3 | ✔¹ | ✔️ | N/A | ✔️ | N/A |
PyPy 3.8 v7.3 | ✔¹ | ✔️ | N/A | ✔️ | N/A |
¹ PyPy is only supported for manylinux wheels.
Extra materials
If you want to know how this library was created & how it works internally, you could take a look at these articles:
License
The code in this project is licensed under MIT license.
By contributing to css_inline
, you agree that your contributions
will be licensed under its MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for css_inline-0.8.4-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51a37c8097bbcf158b74ee04f0f13b315561d74497566bd0420beb4a7c0525d7 |
|
MD5 | eca5d58e21d0a20d54f1f8dc428cd033 |
|
BLAKE2b-256 | ba3ad0bfc1b8b2c787b3a37798af3873a978428803536d77dd3e87e5d4e7682f |
Hashes for css_inline-0.8.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59f2f096bb57b6f61e0a6d7155e9516cb85dc662aea2d34eb8505565791510d5 |
|
MD5 | 6c1bf2c5df7b7525a2f70265e0c05b24 |
|
BLAKE2b-256 | e78f9f2ef9b2f47a4b21c1b94e53e15ad9a3ec29b4a624f177b4ff6dfee22e69 |
Hashes for css_inline-0.8.4-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48b417729a2b1541a242c6c96426017aedbc4c60d2855130e26acfdc70f7c15d |
|
MD5 | 68ed9831a0e3689d813a930692158434 |
|
BLAKE2b-256 | 24115c041f91142b9a7528b930db4b2f02558cc4b9e3a8c0bf747a2c1745b675 |
Hashes for css_inline-0.8.4-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62059a4703cecffee2f57f741d1a4dd8fdb7c24c954090150a6232c00903fc5a |
|
MD5 | 79acde267328e32063ee4c5f14d00be1 |
|
BLAKE2b-256 | 030130a6b66ee68e4012fa48b5d0c2ed647c957e9bb838524deb432bcb881c9a |
Hashes for css_inline-0.8.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c81ca752d2c363da6755f5e467f67a2f0bb8d189e42660c0416644b44202432 |
|
MD5 | c8411223b5eee8a6bdd2ef59215af522 |
|
BLAKE2b-256 | 1bcc7567c54625b99eb6cb70312a37a23b414ab395424c471a2a74d20b727556 |
Hashes for css_inline-0.8.4-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f64275f795b7c57859f1ee0024486d5e387d7877738b926690f172f75293d05 |
|
MD5 | f4d3d0ad8aece10f392d9dea377740a8 |
|
BLAKE2b-256 | 73f6f993da0a0f2240a4b033a2dbb62e3ee3568901b281580de61e36a3a0cf12 |
Hashes for css_inline-0.8.4-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e338fd2eb8c6525a6a07a6003df350be58927a29aecd46ab2348ce52aca1b7bd |
|
MD5 | 6851a2d8d94ed179090a4537b60f5c9f |
|
BLAKE2b-256 | 8ce0d19480c44e3e0e12d05e6bb010333a7683b3e557ced4bbc05dea82ad6a6b |
Hashes for css_inline-0.8.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddb2a19ebf63f77e476d3f23f1137207ba64e6048fcb5c89b87fccff313b6724 |
|
MD5 | 1fd905a17d2dc7b422e2e560615bdeba |
|
BLAKE2b-256 | 5b5ce8c58439043fc151150fc339575a0454d3f6e23d80dfa87c50e096cf653a |
Hashes for css_inline-0.8.4-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 637ebf0d82a9306cf30865fc5b256b1db658eb1ba6713a28d5683e833c1ff31e |
|
MD5 | c0d0b1d07f968a6876c9a11ee869c7ed |
|
BLAKE2b-256 | 701d8abd434cf090742d00156cd9d02067a46e7b00651e453a5e8904dd4c6f90 |
Hashes for css_inline-0.8.4-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51b897f2981ad6f029a4652d9f982fe4437e194912375e33e2581c2676147df1 |
|
MD5 | 3f545add4dfc28dd0088addc1810f366 |
|
BLAKE2b-256 | d2d435f845b80fc229666b0ead9f269d7dbc9ba97652bf8780ea937b30b70a6a |
Hashes for css_inline-0.8.4-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03cef086c90c3641c455a41efc03df3e00e73cd05d6ca292ddcf10986d241096 |
|
MD5 | 6a1221904e4782811d4843530afadbae |
|
BLAKE2b-256 | 591206864d04c84164710fd0e38c715d16479f17d1fcbb7eae6d923eaae5b097 |
Hashes for css_inline-0.8.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9c943de5a6aba74dfd776a176fe2b7b201b7e77b972b51caeca9a7716e2310d |
|
MD5 | 807f61e8003112c24fb0e43cdb82e4f6 |
|
BLAKE2b-256 | f2de970f24076e6c5ada06211ec8e7f5d695a9fce044d3d6026e62af93df8273 |
Hashes for css_inline-0.8.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d67e1c911e64e905e74cbbeef8bb913fb5ada86b5ba432a5d8051329e58a809e |
|
MD5 | 9d4d1680953cf94a17b64bb8f76309dd |
|
BLAKE2b-256 | dba1e75335aebca72bd6b14d05481e7ce0d9d4269ff44c1eef1ee7a027225d3c |
Hashes for css_inline-0.8.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f87ead92817131181866dc4f5ac35d76f8e3c0762bb4846529cb6e168826b79d |
|
MD5 | 8daa82e8e902e6fd43830f01c8aa7ebc |
|
BLAKE2b-256 | 274184e2f17956f8830610c0d3833f5d5c6fbac57d12c61e084b762aa0cde036 |
Hashes for css_inline-0.8.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b5292f851f1ae2b845dddc97d21f7525a88da0521acfc06fbda63cb8ebec76b |
|
MD5 | 1310dcfacb55ff2087729d2396cb79bc |
|
BLAKE2b-256 | fe1cf56971873c792671c592afe73b3d96851e8a27279053688033e775f84d85 |
Hashes for css_inline-0.8.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 906cc294fedae1f645c5d40bc479e9140d694b5960a926aff001ed8b0844cbd5 |
|
MD5 | c287eb415484b58cf81477d9a739f19b |
|
BLAKE2b-256 | 863247055a278ea0d958bdc4e945f32261caf472009e961072d4cc99852dff5b |
Hashes for css_inline-0.8.4-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f222e9a6ebbb6d912469e4ef16845090c5c9fdb34903ebc98851966155524be6 |
|
MD5 | 6d477254bb0e0af98f7a8b8b9f4033fc |
|
BLAKE2b-256 | 9b83915619fd236a853013a7d44b081a427e767987a11c4cae8d641181c0366c |
Hashes for css_inline-0.8.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cac71b716e428264786563852eac604c5048aec84dcd69e8572717933f327969 |
|
MD5 | d8f4a524973673e7a6e6e516edafd5c4 |
|
BLAKE2b-256 | d76109c9a1e9e936e8a71a64d22e83df67e66dd18c271a9229501450d3929f52 |
Hashes for css_inline-0.8.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3e1309d16bd372b561984d309da556705cbf2a48a8bb1f243257dd0d885a1a2 |
|
MD5 | 050df7812e7bc5f050e1a010ca6abc2b |
|
BLAKE2b-256 | 4a569338e72e4e6555282fc7594ac070b24f68d6f8c8a92cb6dbdfee49b594ea |
Hashes for css_inline-0.8.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b1f7a0ee8331e11a92b76381ecbefb55e2e7c64a5f78e39229cd15a4369c4c7 |
|
MD5 | e8243084795764acc83935de1b843b0c |
|
BLAKE2b-256 | 18cdce5b82af821e7246ccf60eb7eea6bf34ca360e69b84b8ad72ec09b757ee3 |
Hashes for css_inline-0.8.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed066e89d217007045d7d9f89785394adfce326d27d85c179f871411ba16a558 |
|
MD5 | ecb08a2ad842bf2f9f4d9dc7c10e51b8 |
|
BLAKE2b-256 | c3f6e5751647055794ef7578044ae20ef1167e2c71341cefdc6ac9dd5d7638c5 |
Hashes for css_inline-0.8.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ae51a523548dc30289a9e08bf029199e4cb34462afbed846320b8a9664b283 |
|
MD5 | d9cc0531a453d501d37cc4d7f03e78ac |
|
BLAKE2b-256 | 0441ce33a89f48ce7c5b896e95bd24ba4fc2bd095fc61261f9748e6c4ead6a25 |
Hashes for css_inline-0.8.4-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a85ac91cd2ec49f53ae7dd9bda458b0de66fc530a6fc92dd4d23102d3d993b93 |
|
MD5 | 33cf5619f690bf30ad00a5d7046eb4ec |
|
BLAKE2b-256 | 35ac8d081c15d0e473f8a31405fbfd48bdc276337e80c0d003a40ea0f61d039a |
Hashes for css_inline-0.8.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 204819378218e5d790f720e2576d17c7e0ba02cf06b26f4aa3fc0ddc3ed738f6 |
|
MD5 | f9b3e47d0c80c91d4a3ccdb81119e067 |
|
BLAKE2b-256 | 7bfe3172beff7b7a224ca680175d2747d77bec9a72dbf7554d1cce91365d9cb8 |
Hashes for css_inline-0.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d27bcf486703f647b3754dfcbeca829246f8290a5be1713a4ae69128ca8513c1 |
|
MD5 | 37b4ae139852e4da645287a125a34dcf |
|
BLAKE2b-256 | 9d618f02a095f9ce171940b14a76a59d4d5f26a1075778a0adcdc2035e29bbce |
Hashes for css_inline-0.8.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 278cfe84d56ad21aa07c8f25c24141ac1a0e9c72f08d8f73a9b82ff5c32795a7 |
|
MD5 | b288919f3df7c750ba6db8d20b967424 |
|
BLAKE2b-256 | dac324bbc931af55458c0e50365fb0b559b24b06e09f9e433be20a956660aaff |
Hashes for css_inline-0.8.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64bd985c1680b6f5da38a729d8c72bc92bea8852ab4f8f04496f4ab418f44b7a |
|
MD5 | d3ca42b0a9450aeb6c86459ff691d74c |
|
BLAKE2b-256 | 94013b90797a63ad465897fa1d0cbc3b87e05c7dc95de41b9bfad6a6c58f11a6 |
Hashes for css_inline-0.8.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f05fb24b108c5d74345f22f814f5b6360663b68aa699c5c1eb615261fc57f9c2 |
|
MD5 | a12ffe9710f165db0b3209a0791fe48f |
|
BLAKE2b-256 | ef012530131606c12f496d4a0173246294054b08fb1bfec83854e1a8371e6fac |
Hashes for css_inline-0.8.4-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4955e1bc5f26403e5bd85219a58a959461e93866b91a31f26cc7a08595f43dd |
|
MD5 | b362c421bae7fcb6101616f29ba1be2f |
|
BLAKE2b-256 | 8cb5a72caaec1d69dfe09de43a17d175089a0d207845f823fb9428240b64d783 |
Hashes for css_inline-0.8.4-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 383d0d907ad53ae0aa4589a4a89e5fd11d6cbc9a4cb6eb4ea7a72940383079c9 |
|
MD5 | 6f593338014d4c9bd655a7e4a377937a |
|
BLAKE2b-256 | ea5eed93bf5a95c184daadefd34fd236bf85bb062239ed40df1c6c5992c927aa |
Hashes for css_inline-0.8.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f867ee2fd5ec661d5ad85d679632e3f550b1cc82bde71730a0527a88841907 |
|
MD5 | d9ec18268f67572fbd06f2eca0eeca03 |
|
BLAKE2b-256 | 694702cca3e4e63f3ea80f1f3cb6dff54b072437bd0c905ebe7362cacf85dc99 |
Hashes for css_inline-0.8.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c83ede936c3d4b185ddefada5aba07459c3a99ad9d9a65744303cad88664fbd6 |
|
MD5 | 634bd5d5e31021dde1037027c396eb7a |
|
BLAKE2b-256 | 86798130da2336ebe46a4578e6fe8d84bcd237a22022563020d5fdd0c7093a18 |
Hashes for css_inline-0.8.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 240a694c188361ecd1e705ffbc676575f4e64b13e96080f2a699d8fc5b7d695e |
|
MD5 | 9b2f707481b5120471a22122e15117c9 |
|
BLAKE2b-256 | 8b85462041a9f44c8db71ce5a75b80f9e3b1bec799813f2ce114c3e40face790 |
Hashes for css_inline-0.8.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d15c21150c0ba58a6d1d2b441fcce1feb0229de46d7eac8fd986963913e4d6c7 |
|
MD5 | c4b1d9f800ddbe83acba25e369da1714 |
|
BLAKE2b-256 | 5b1992926904c4da6d92c39f337f9b3456e3847895a9826ef96e6c09f451332b |
Hashes for css_inline-0.8.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f2266f18d0f6faa3a275dd05dde4edc1b720389018377ac5b6dae131c600773 |
|
MD5 | 26d0728a1f2783f6abb1438b66a7c2e4 |
|
BLAKE2b-256 | 7d93df847df35e78357c4b9fd063431899ab95c72a4016826f02e78308fb56bf |
Hashes for css_inline-0.8.4-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17b42c646137b0591e895710461f7eda4615dc09389102a5676626d73756de59 |
|
MD5 | d61bc59a0cbc686e97cdb1fa34f36353 |
|
BLAKE2b-256 | c0ad114537660efd0d7e66a53a895de593cfd1257bbf07851009bfffa9ed7276 |
Hashes for css_inline-0.8.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c17a3e2dc7a7a5a984d3ed0004666e9ba98a461726741502abe1ccc442f7f232 |
|
MD5 | d1c115c778541d7940e2c403a76d22fa |
|
BLAKE2b-256 | e882c4a016243ca631b15f7d1c861b5fa02f2c63c66e73130c138e37f65015fc |
Hashes for css_inline-0.8.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 605e93ed565eac8f5eb8829a2a62da0b6503f0913a1d1c9af08f84dd5ae3a025 |
|
MD5 | f8f2cbefd4c223ab3ee4aac1f24d126c |
|
BLAKE2b-256 | 174d46fb3785410cb6c2d1d5b0be8feead1e487fa166688fba67681fedbc74d1 |
Hashes for css_inline-0.8.4-cp37-abi3-macosx_10_10_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c9940d42b778e5603b11a8c106e58431279163314db45627f41458fad16dd9d |
|
MD5 | a1b60e23cafc2d340feeee057b70ac90 |
|
BLAKE2b-256 | 18561ce0b4ec23fc911d68a88cd694142464852cb0afd11873a37850be69b9ad |