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.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e66613a05cde3d52f1d3b906e4d1e9f33a7bf774c8326bf7ff32a84b2142784 |
|
MD5 | 0580ed0321abbc3e8a70ce030e044433 |
|
BLAKE2b-256 | 4845bcdc1e62028abb283fbed9201e4ddd588bc7ba64ea73fa77588a7a863730 |
Hashes for css_inline-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccf077c1a8d6611f462770cda779ea904718e8cbee927633be730f7b7a3e4ea5 |
|
MD5 | 98ae754ec5cf81791f410e83a6c6385f |
|
BLAKE2b-256 | ba59991edab5775b580a36a0f40ff2585f8e097649655c2c5254c051cb57125f |
Hashes for css_inline-0.7.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df6c5870bd861dfbe4103c6a0e4e05e24c678eccf257d72a1c28c8b30e0d59fe |
|
MD5 | 9b515e74d1f9c02bb927c94a51a6e4a0 |
|
BLAKE2b-256 | b352b66366f9086b09314338d17116fe1968f544cc901ff200a0bdd9cdf4702d |
Hashes for css_inline-0.7.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee10702428f79ecf1f0d8274a9cf06c38f84af30c33b4e76545269b2b61b97b4 |
|
MD5 | dbc9c9ca3380919451d1eb9ef31e8cd2 |
|
BLAKE2b-256 | 50eeaabc6310a5d9e70342afdb1b2e21a1ddf028122f5c37d9a20c8dfa3102a1 |
Hashes for css_inline-0.7.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29b1ee8562b1f227d4cff926c43617151ecb7f801cd8bceb28f1ab8bcc938c30 |
|
MD5 | 9c63c7b6cab3c291e5e261f7d52bd700 |
|
BLAKE2b-256 | 4536a82bc418258596edaf0b99d8d2b510b04a9ae3b2d1f5233e975906fff82a |
Hashes for css_inline-0.7.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7112fd5a0bfb1706cb3688177b83b986e2c7159ecde859e2adc6357b11ad7b50 |
|
MD5 | d439dc1a5d06139c45bde9686b27094c |
|
BLAKE2b-256 | b8648986ba3afb01997316b3698a77f41150379a0d963763d3619b604fe20df4 |
Hashes for css_inline-0.7.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe51b35c75228dcf5df140f3b86fff134dc71bcfc4985cd0dd3c781789dd2505 |
|
MD5 | 05a5f4f099fa2bca19d2c247d7091829 |
|
BLAKE2b-256 | 68c4d61993a6687e8c7a97cfb8a56fe7d7c20317c65d4521306630e97279553f |
Hashes for css_inline-0.7.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5f632f806ca042573f2b4b83598d02e3aaedadb9938d5d2ab5db77b2b64dee3 |
|
MD5 | ea6fba812c06c73af8fcea7565f7ee57 |
|
BLAKE2b-256 | 1b416f8d8770f3e76c219dbab291fcc1e538e3bb60e55f31c849db5fb5d771a8 |
Hashes for css_inline-0.7.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26cebed333299b46fb2d4d66eeea57bb2a4d7192aaaf8582ba688af473447793 |
|
MD5 | c9476dd2d836568b0682422be6af2e3a |
|
BLAKE2b-256 | f448b8960ed1c83da48fca66b876bd4769b12240c1d0bbdccd716b23728cbf6c |
Hashes for css_inline-0.7.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28e321ad49bb86521dc5a20f696a523334a1c1f74b5656a63d2e059b37d3e822 |
|
MD5 | 2d70eb88fd2f4518158e0ab0e2070d2d |
|
BLAKE2b-256 | 9934e8a90d79a2b569125305bb941e9e9dda998ae45ece9ba8edb2c00faf8f24 |
Hashes for css_inline-0.7.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccd2f53a05118ca498d55efb4c77feea189f8f1c66522b3321d9a48881cb1fc3 |
|
MD5 | feb6353a1271b66832105df2555f6496 |
|
BLAKE2b-256 | 66ad73e882c0a03ad035c9869b827287dc109edd95915618fbf8f0bad88e4071 |
Hashes for css_inline-0.7.2-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc91dc2d460288ba62d1d115cfea2b0fa897d7e944d62f5e9778e5181d0f6af |
|
MD5 | e4e7145ad6758f5d75516a156f583817 |
|
BLAKE2b-256 | ff82de28a2941928245238478e315baf91775e5784df2bfcafcb8e45d580c5a8 |