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 then 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.4.0 - 23.84 us
premailer 3.7.0 - 331 us (x13.9)
inlinestyler 0.2.4 - 2.45 ms (x102.8)
pynliner 0.8.0 - 2.81 ms (x118.04)
And for a more realistic email:
css_inline 0.4.0 - 491.63 us
premailer 3.7.0 - 3.31 ms (x6.74)
inlinestyler 0.2.4 - 61.78 ms (x125.68)
pynliner 0.8.0 - 92.68 ms (x188.52)
You can take a look at the benchmarks’ code at benches/bench.py file. The results above were measured with rustc 1.46, Python 3.8 on i8700K, and 32GB RAM.
Python support
css_inline supports Python 3.5, 3.6, 3.7, and 3.8.
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.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 838b9e2169be9b7e62130d551762af25490a7b877ff3e594fc975d1bcc28aad1 |
|
MD5 | 0987385b1c5d08731926dc6406beae7c |
|
BLAKE2b-256 | f093e139385f5507a8091f6cf258e6703e3d19bd74327b01c23e55c06eb66c01 |
Hashes for css_inline-0.4.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e46c9eb1d59351d65a1222171d28d32a512862f59fe34497606fed0422c7efca |
|
MD5 | 3c4c411c7196799f07b662075c5b9167 |
|
BLAKE2b-256 | 91570ec4e19a1af69883cd95e3e3294b8a87a57fa3c27e7abc82985840575a34 |
Hashes for css_inline-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e54f2be1fbb92785bf525d89ec4a52fbb9fc1aaebe09edc86bec5c3ff2860ddf |
|
MD5 | 362c322bae0e0ba185bf24c33eee832c |
|
BLAKE2b-256 | b7556b2ee01a11e94378d4b145a45f9736b815a7bf7c8a5309c16a66ae57587b |
Hashes for css_inline-0.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db8d03302e4698bdd70c05d78c97c5900e86ef84fb7b4860c864a4f03db1208b |
|
MD5 | 460d8b4e2645961c7cd9a43b0ce68b6b |
|
BLAKE2b-256 | 712422fe2ee40241adec9516d04e2a2dd10d62ed0aa8600f22ef83012a76ff46 |
Hashes for css_inline-0.4.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20e7e6173d128fad3512025eb042112c274354b4bdc903d8f17dedb1102d7251 |
|
MD5 | 1f1f47eddf270de59914591aebaae905 |
|
BLAKE2b-256 | a70ea0cbcafdc55d7b8d4b5af780c45d2bb8e3a42cf1ccec7d1d96b0471a317a |
Hashes for css_inline-0.4.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b573444f02cfba6b7fbfd47bf01cf0a6d41a85dbde20d4ad1b5a1a8894c113df |
|
MD5 | 74373b82bf55058da11d8d45fc947931 |
|
BLAKE2b-256 | 27b66973764858c401f54a6fdfcfd6ae1011e1ffcf9faa81f21e06f1b19f502d |
Hashes for css_inline-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b97ef326ccdc4b0cd50dcbd970961efe9a426231884fd1c0e2bc61c28d803e8b |
|
MD5 | af99ebf6ffdb78ff98e1a424ba42a9af |
|
BLAKE2b-256 | 1e0ae93a783d73c98c8a6b7c3453e6fea7c96aa8137d468b5c471fdb624ff360 |
Hashes for css_inline-0.4.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da03c68a70f0434cd5d973f5c597ee12cbd2e5a8c3369536982129a3ded9de3e |
|
MD5 | a5807713644e6b1df520c14968078989 |
|
BLAKE2b-256 | a2cb0eac0f8d27c3ac85ec908a51611d81541dd3d5cdda54270e147efa0da4f2 |
Hashes for css_inline-0.4.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f42740c942a34c160a2b8a7359a05cfe138b0662907890bee9cc943d39950e3e |
|
MD5 | 90f4fae5916c759bf54b365f914ad1fb |
|
BLAKE2b-256 | d8574e96f5c877ffaaf15dcac97eb0a7a8e58eec5f3ada821b7ba05a1cbf750c |
Hashes for css_inline-0.4.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aae87f2f2f7e41c4cc65bf7ae54e3e06ada72627e7032763b20e397a16305e5e |
|
MD5 | e6102728e7d7cd478c29db4be6a827ef |
|
BLAKE2b-256 | 29f1ac3f45ae555a267b2e452c02df84e88cc033e26e7ecb5209d539c53199f4 |
Hashes for css_inline-0.4.0-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f875ed4b89ee5b86ca4232bfcf9680584075948fec8c81d11ad65c4a6867830 |
|
MD5 | 8f01a5115c787994856638e6852b2d63 |
|
BLAKE2b-256 | 09d630d93c42735b521dcb0a6f8a74322ddb9f3c3cdc5d16b7c550b367771ec0 |
Hashes for css_inline-0.4.0-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f16baf0535e78ae70dae5ab797b67214176012d53d1ebd4b97c6849835be3d46 |
|
MD5 | 9be508a3e433d7979c3eac8a70341403 |
|
BLAKE2b-256 | 5d590050300fdbf3b296cbd6b88b1119b0963c15f2fe254d44e72b1721544647 |