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.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 499f09bcccff4e16066ade8207b17d0023f0700db9c260790d4e99924656a4fb |
|
MD5 | 7efdcdc090f2e2738b855dcddfba8d61 |
|
BLAKE2b-256 | cec2c28086bed0672ff16f2f1b170ccef52a44901b46441d0a781856d2bfb74a |
Hashes for css_inline-0.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc0d55371f998ae424946fa89633ef57a73bdaaea4fc24890704f52cd77dbaca |
|
MD5 | f29dd1846952c2189aa8f643aacd4332 |
|
BLAKE2b-256 | edfa0cb381c26ea3d26895ea65f725c4f0a831433aa25a9e88a66e017fa586c3 |
Hashes for css_inline-0.7.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba248e604ff684ac3bf5dea8c124df2710c613cea0c902bd6c97c13f02cbec29 |
|
MD5 | e9a0cc61a9649ba0adb778f0ab2a3121 |
|
BLAKE2b-256 | a43106b2ab500724152b75a9db7b0ce03df3579f7de126b7ce7b8ecc924647bc |
Hashes for css_inline-0.7.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f70a6b6550c9090811b4bc8fd14134db0975626587500c6d66fcfdf0df253f1f |
|
MD5 | ba42b8f85f3656c268ad5b055b2bc5e3 |
|
BLAKE2b-256 | e8653c7b4976d23f3de27613da1df7233fb476ef887d57df3fabd79b80ba4076 |
Hashes for css_inline-0.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01a7cf4d1cf94bc991ddee74a3bd6da9bc8cd83c2e8860fdd14863438e0bf6d9 |
|
MD5 | 04a6602962f32bc50b8d3f55101f2440 |
|
BLAKE2b-256 | 30898edf9db40fc6df33365d5c5da2db67da866994bc59ec8bd2dec5aa4dfef7 |
Hashes for css_inline-0.7.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddea9c6c05468f1747510355310c2a606d527b15624c8ddd88b3b54e17ad3799 |
|
MD5 | 68cddaf8c0b25b419e29fba96de75cdd |
|
BLAKE2b-256 | 8f0c37c33e9ae6b0b12f14d2e482fddbc03504469aa75ba9393ea8fdad1df8dc |
Hashes for css_inline-0.7.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 752017e0e3db4998862e2935df3a7b3092b147f076b7fcdc50452afb62454c21 |
|
MD5 | 927b27a20da9024ad55252af85c2b960 |
|
BLAKE2b-256 | 875a4cfaa60e5b02edef95b873a4dcb8c007abe6749e5bfa6e4b223ef4d06487 |
Hashes for css_inline-0.7.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d243e6edb64bc18b25d0ec297eb9c121d2119c18a3ad4f6edfe681c42786a2ec |
|
MD5 | d1240fe5cca8b3bcb2e36f9823d2b011 |
|
BLAKE2b-256 | 6d40bd3927fcf2fcad9440ad46c72e54803ef447f85cfc02e707bc56265c2f86 |
Hashes for css_inline-0.7.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bca36864e5a06f1c3e451ff3a74f543d7539eff39b084e3a7c81e89f91562375 |
|
MD5 | 4fa54bea0ceab96457ab033a6c67a647 |
|
BLAKE2b-256 | 70ac3b1eb4efbc2884fc12aaab5a5e323bab2a8d9af2ca1ea79ab373f918e7b6 |
Hashes for css_inline-0.7.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 618d60722a1710ed3b87b6300fc9a15b5d35169bfcae5bea88334ef5b4042819 |
|
MD5 | 732682493c170a9ce8112871af0c7a1c |
|
BLAKE2b-256 | d7b4f5e10b244652fbbaf6ef49fe1927a1d5b9cbfe0388a6ac6e7d93c7232d23 |
Hashes for css_inline-0.7.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47e647f85228c7492b1e05100cda3637b70b011bffab92ff1bc1488b0653cc1b |
|
MD5 | d1a4716fd2727deb3ec0adcf64627d6a |
|
BLAKE2b-256 | ba8c970986acba6be6577f9d6af5331701a54f437d3af33e95eee3ac897a39bb |
Hashes for css_inline-0.7.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a5ce50e142b3b42f717a133b865a2f696c26400de77e37c35d22c0c4fecdb86 |
|
MD5 | a419b745a772dffc2bad4fa7f747bdfa |
|
BLAKE2b-256 | cb750eb185b66d4b3ff4f87f915834b6f9fac3ce4aa8755a7fc8718f2ad687da |