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);
… more features will be available soon
NOTE. This library is in active development and provides a small number of features at the moment, see Limitations sections below for more information.
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.3.1 - 23.31 us
premailer 3.7.0 - 335 us (x14.37)
inlinestyler 0.2.4 - 2.48 ms (x106.64)
pynliner 0.8.0 - 2.82 ms (x121.27)
And for a more realistic email:
css_inline 0.3.1 - 482.79 us
premailer 3.7.0 - 3.38 ms (x7)
inlinestyler 0.2.4 - 62.64 ms (x129.75)
pynliner 0.8.0 - 92.18 ms (x190.94)
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.
Limitations
Currently (as of 0.3.0) there are the following notable limitations:
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.3.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1be43bae76e809046439565e709fdb01f8ed1d1be2a0782da3a6e7db99d01ed |
|
MD5 | 812292339ef526af99fa4210853f038b |
|
BLAKE2b-256 | a6831634ed615902bdd366e763ddef58a1b42caadf92859f1f07a953cba9e266 |
Hashes for css_inline-0.3.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bcf29b99d513bc6fcc51d960d5aed739ac35bc69ca587b0fa6d523d02182edc |
|
MD5 | c34d83d24ccae93ce1d155c55020fe29 |
|
BLAKE2b-256 | 9a39ab084b3aba0d4255a86648ab93c4e8cf9164a721d06eeca8be2504890861 |
Hashes for css_inline-0.3.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a84229fab820de241630c5908fc0a195164cc898f3cb8986184e181e7130557f |
|
MD5 | 39c895798e88517f4783a74d24896757 |
|
BLAKE2b-256 | f036aaefa284a5ed4a210d18b4ab71324c3fe56682ec7c51b2797dac7cff2fa6 |
Hashes for css_inline-0.3.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63d082e14020bacc09c01e823341fa9bb90626c92c03ac957047a004e543bcde |
|
MD5 | b66be70165068e7c3f6ea061e6ade899 |
|
BLAKE2b-256 | ce6058a2f4347c2af877ac7bf28ce82110df523c98ab60d787de698c58d15870 |
Hashes for css_inline-0.3.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd7cf6d9ce81f18f8c3607723ea81033c834a2f0085e0278b63c20848559b077 |
|
MD5 | ada4a097902180559c3cf40563151b1d |
|
BLAKE2b-256 | 33efebf538d19aefcdc37ab8039c7f9344fe6a752a5d86c6895cbf958b0d05ae |
Hashes for css_inline-0.3.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3169b1c2de534c7e7a32e62202c6b9c960ee2f989250031db484a50a269937ff |
|
MD5 | c5227c6e072690f4d582a4875beaa2f2 |
|
BLAKE2b-256 | 9ab3664056362938310fda0145837c55070cac55032a3c773c9a7677e8e35b83 |
Hashes for css_inline-0.3.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695b8ecac700a0f4b648ed010ac9d7e369554f791667adc95e09eb3ff8d7b051 |
|
MD5 | 5c124b57ae75d96f2f2e872a1b5c79f1 |
|
BLAKE2b-256 | fe2742a2ec5a2b64d15325f44c4c93be33c347b0e4826ae561ef8e7243f0cd42 |
Hashes for css_inline-0.3.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b23d176a974d4eb929e2c10315678b2c546cf8e0b503c06a97b7cc37ab6c981 |
|
MD5 | 246567135ef578bb3d0ab94c4c415bdf |
|
BLAKE2b-256 | cf5ddca1c5e157d838ae16cfba4693f27c630d73d56f780410efc2b09aead5ff |
Hashes for css_inline-0.3.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dfa7c7e5a38a00c04e5955f78672a85df6a796cae1678a3963577e9cd8dab39 |
|
MD5 | 18d3b537b38787f295a571c55bb6350c |
|
BLAKE2b-256 | 4fd4cafcacd468002d63afff7d4b3d28a8c95af3c3761f5c5291de6368aeeadf |
Hashes for css_inline-0.3.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96d801b52bd6671e28762e86554c4607efa563d0989166ff9cb3df4eb5494f96 |
|
MD5 | 156d402c814ec0959c2fcee9322f6e49 |
|
BLAKE2b-256 | bc0ff280f6300ba46a3fafbeb04c6a6cf7b422df36b5f286349303135379bf57 |
Hashes for css_inline-0.3.1-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63c305413a9d2b68ad3479275ae7a484729144fe3fe07224c14db8054dc52edd |
|
MD5 | 536c9edb755a1efd67144d59ca173a89 |
|
BLAKE2b-256 | 4d022e9a685b8aa426515289d9a85c2210910182cd9b6eafa5067f81ae1f41c9 |
Hashes for css_inline-0.3.1-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d74d2c0c60ef32fd29cebf2fd690bea0dea33b165e4e28dc214b9f86ff9eba10 |
|
MD5 | e0089f44dcf6db25dec58cf6cfd60986 |
|
BLAKE2b-256 | 0e09b55590c5d954644a86d419f22202e991344d4a10d8a4ed7a15e0f548f988 |