Fast CSS inlining written in Rust
Project description
Fast CSS inlining for Python implemented in Rust.
Features:
Removing style tags after inlining;
Resolving external stylesheets (including local files);
Control if style tags should be processed;
Additional CSS to inline;
Installation
To install css_inline via pip run the following command:
pip install css_inline
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)
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(["...", "..."])
For customization options use 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 good performance characteristics. In comparison with other Python projects, it is ~7-15x faster than the nearest competitor.
For inlining CSS in the html document from the Usage section above we have the following breakdown in our benchmarks:
css_inline 0.7.0 - 25.21 us
premailer 3.7.0 - 340.89 us (x13.52)
inlinestyler 0.2.4 - 2.44 ms (x96.78)
pynliner 0.8.0 - 2.78 ms (x110.27)
And for a more realistic email:
css_inline 0.6.0 - 529.1 us
premailer 3.7.0 - 3.38 ms (x6.38)
inlinestyler 0.2.4 - 64.41 ms (x121.73)
pynliner 0.8.0 - 93.11 ms (x175.97)
You can take a look at the benchmarks’ code at benches/bench.py file. The results above were measured with stable rustc 1.47.0, Python 3.8.6 on i8700K, and 32GB RAM.
Python support
css_inline supports Python 3.6, 3.7, 3.8, and 3.9.
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.7.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1464d153589667872a6a08bc969bf4a9f93ae1168b136353594a969451ffcd06 |
|
MD5 | f2ecdb1d65ee00a81eb4318b79622129 |
|
BLAKE2b-256 | 81f9a52a95f2afba1b3957ba0051c02e77e2ac169c5b8b7cea3fc58cd3270fd7 |
Hashes for css_inline-0.7.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fafdd2f484d435d8b0c994190d1a06ab743fbb75e8fd39a89c400bcd42e4b0f9 |
|
MD5 | 71948b334c6c775be7a8c66bb4c98ad0 |
|
BLAKE2b-256 | a285ad3fb7b6944f88bfa17a234ffe3f090d21b00da2e1aa83980de7612f213e |
Hashes for css_inline-0.7.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b4cf86e5581c9a3e779e9ecb435cd77a30422c57cc4f3f88f1c12776108bc73 |
|
MD5 | 199a59e70e4a1c1912a052eba38b1408 |
|
BLAKE2b-256 | aea6da5a8ca471bcf71be7b041a3c2daecb6656aa91b33a520c2fad885fa3b7f |
Hashes for css_inline-0.7.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e06708ab6436476a952d79ec8bb1b2e9500405dd7c29d05732ea3dc2159cd35a |
|
MD5 | 02617e6e9a7b53cb948bd2534b7278f6 |
|
BLAKE2b-256 | b88ee132718271d153a42b7a9e5a7b43e19efae4691679e11b564a6c350bf11c |
Hashes for css_inline-0.7.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b794be9226c1736e1d1afbb4dd6bc055626d6df2066c765a23371dfb5340aba8 |
|
MD5 | 2463616d8a9da0d50ab8a396fab4262e |
|
BLAKE2b-256 | e203c60877665afcfe15bed7d923ffce6490ad42e54f7982b1b3e010423655aa |
Hashes for css_inline-0.7.3-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7943d406d8837a4ed7a37db5bc6d0671bbe28370840892b95b4b7314ab2f262 |
|
MD5 | c1488aac916726766d6e969d9c9f9221 |
|
BLAKE2b-256 | f0075edafbf48692767e8082fe6fb7314feeaeaa5ea07886f01a45e5154b3149 |
Hashes for css_inline-0.7.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2e33b9b9ee1c45ed2145dcd7626658ea10172bf860e34720edb1e0a5d274a08 |
|
MD5 | 1e3bfb1f9ff3b886b4b7b973b0b2968c |
|
BLAKE2b-256 | ce3898e5bd95cdc221f76eca7ce75b3cf9bf3b01b857a79128afb69af61a0028 |
Hashes for css_inline-0.7.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1ddbfa23e662d3f8eccc1d0716e55a91a32be3d3bad3cd3d09bb3b5b0857d86 |
|
MD5 | 61169ad06d8ef1649583b2c69a129c58 |
|
BLAKE2b-256 | 7428a516ea3ada9585cd7947002a8b2aec48d7a856ce8ec95b8ef05dd24f6fb7 |
Hashes for css_inline-0.7.3-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 229f2a6cfd28b566618d53a7b34c62be813405a63e19d3e79f7e26f27f82f542 |
|
MD5 | f0fed0cd27ffd36c2ca546dfbe3549bf |
|
BLAKE2b-256 | 9096f1d409d323979df8b7f39830584822b0e9b17dbb241846fe147e47abccb8 |
Hashes for css_inline-0.7.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6a2134e0a17e5e7ba96679612461d4cf8c2f516e520f2b24143243f8bf4396b |
|
MD5 | 4e8829f50b5c9c7b8a0b9497fc757a1e |
|
BLAKE2b-256 | e256004881f5b17a3d764524ac2fcbe535ccc80ac56f1d3dbbd5465f11d18190 |
Hashes for css_inline-0.7.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a24a40eaf47cb0bf07ffa972d57775276a5b6bc27c72a914f5db27acf0b726d |
|
MD5 | fca9179037daf275f3d963d03e3a5a00 |
|
BLAKE2b-256 | d95072b20512fed913c346005e1e73ef52dc0a613fc2b2c346cc1a3cabdaf83e |
Hashes for css_inline-0.7.3-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c085188f90a77390f13dcd7e1dfd5730635e91651ed4700c991f884d66f089d5 |
|
MD5 | 5027840c80f25122c0fbdb87b6934212 |
|
BLAKE2b-256 | a74e10143798f04f5968eeb6ba76f143122917a1e3c428acc6d3ca92dd3c5244 |