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.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d514515f4c62debd8729537d41fa0142bb15b2ce5111b8defdaa4e7efb20c3d |
|
MD5 | de05c366a871db5d03857f1452d4d936 |
|
BLAKE2b-256 | 666cf5fadfd31963215441a462ea412adb90751858380a5dd0f2b510cb8458f6 |
Hashes for css_inline-0.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29a3bd7f573a75cd0922b9043a9ea47d0e9a3b2d6e88f5f2b030ff2e449424ef |
|
MD5 | 5d62702f06f216b6cf5f01c04ce9a3c3 |
|
BLAKE2b-256 | 5183c5dfdebf9fd03d98f07e123e52d17824cb8fa1b8116ca8b187dde402b487 |
Hashes for css_inline-0.7.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e15117461a59e6130f6eeeecbaca327f6377089b83ea59258d94cd34f3b8883f |
|
MD5 | 77909c41c8fbc3e8dfc17d848ef22a67 |
|
BLAKE2b-256 | a0eaa2562e59b74d55ef99a3105f28c225e11f9154116584f704a1ce7b53fe70 |
Hashes for css_inline-0.7.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 056107067c1892554c4c1909283ade5d551ecc7207986f9a83e1401f6cfa394b |
|
MD5 | 1d6940ddc4ca71716b7549bf21b94f20 |
|
BLAKE2b-256 | 010d08934248c4fa4eaea5145cd7ee9e8ebb6349d962f02eb3e987561ae1a154 |
Hashes for css_inline-0.7.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e49e01be8dfe1ff4e61a53314dc8d52ac9cb941ab2b7b6074a9347f307362a7b |
|
MD5 | 1ee7e13209f8ad350f87045c24715938 |
|
BLAKE2b-256 | dfa937ac318c40097518a4d074bf90fb077119fd98606af7091df90141966ea7 |
Hashes for css_inline-0.7.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ec81bac823ce5befbb59da09f4e145d69432b62fd16d3449f25243fe38f90c |
|
MD5 | 1a508b70c6eeecc237c6ecf85392f191 |
|
BLAKE2b-256 | 05cc33af4e14d30371f53e02d7b2ba8e584c9a16b08bc5a971367b8ea034a776 |
Hashes for css_inline-0.7.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c1dc8572a4974beddc6a29da7c801de6aa3b647435c400c034f639cf21aa975 |
|
MD5 | de7107e7b5ff937e5ce90ff550922862 |
|
BLAKE2b-256 | c814602da86f25ec5d8239f588789178c3726aac9d35c7a84b4e2fba322cbe4a |
Hashes for css_inline-0.7.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb7341fb58a3a54696356b68da3f08a5251286c157ce65ff6b2cacc9c41840b4 |
|
MD5 | b9d57e8c3bd345da12ee5abc7a7148c3 |
|
BLAKE2b-256 | 62785e79d180e3c9b8e6c5f219f0e18f2f8c6c615f6fbe493c48cd0e4d10b6dc |
Hashes for css_inline-0.7.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdcf50b29d5ecf82a958e0d577711996c85e409ae0e704760a18e0148e2d54b2 |
|
MD5 | 2307916bc464fdbebe026270a3fc9fd1 |
|
BLAKE2b-256 | 5342e1c8170e0f16b6b4697284351f441d4c0681c0892f9cdfc09bdd8506e71c |
Hashes for css_inline-0.7.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e6845993f624ee6dfa4b54ddcbeab7da34ceb09227cffeb424c09c8bbf50271 |
|
MD5 | a40248a9069609d961c85827070fc779 |
|
BLAKE2b-256 | bb10779d7c2b3d38d5686fe9a221879a397d5f48adb16dedb0fbbc4130426a06 |
Hashes for css_inline-0.7.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 229613d4c3c189b224b134266d0b00bff9399fe9e54910df7d1bb4ed5056f643 |
|
MD5 | 3e5fcc7bab1be850ec1f9141687e5110 |
|
BLAKE2b-256 | 12bc2338db6d9aff916542567f132e32558dd377fbb28ed1a2854c385a806c6a |
Hashes for css_inline-0.7.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74324891a391df0340f540322d92f91cec49783f6c0a50d4f90a199a1ec7a3b4 |
|
MD5 | 4ec9fda900c61dde89486e6231a7896f |
|
BLAKE2b-256 | b6c19df371df34d17c240e92180edca502cafeebbc1c06d18701cb49569f3fed |