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.5.0 - 22.88 us
premailer 3.7.0 - 331 us (x14.48)
inlinestyler 0.2.4 - 2.43 ms (x106.43)
pynliner 0.8.0 - 2.76 ms (x120.76)
And for a more realistic email:
css_inline 0.5.0 - 469.57 us
premailer 3.7.0 - 3.32 ms (x7.09)
inlinestyler 0.2.4 - 63.15 ms (x125.58)
pynliner 0.8.0 - 90.66 ms (x189.20)
You can take a look at the benchmarks’ code at benches/bench.py file. The results above were measured with stable rustc 1.45.2, 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.5.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60e06ce62473f0d8ed831e7015904b9252212d529200c9ab7f579b2a03096a9e |
|
MD5 | afdd6768e6e472a2d59fca37e5cd7ea7 |
|
BLAKE2b-256 | d712b9c80f46d6281d36a96bc7aecaa4d48dcdaaf413085e6bceebc09e47b3a2 |
Hashes for css_inline-0.5.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68e2bb296248f743695b66c912a7f9ce72819d3a4ecad1d532618b31ca7cec30 |
|
MD5 | 7b44aabb67845e6c1410f1dd9f4f06c4 |
|
BLAKE2b-256 | c2de68536e9ce6eb0c69e3adfc74226e70108decbc967c29eb73843d126cf580 |
Hashes for css_inline-0.5.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a42e2cff20a634b6f328e3e51ae75634848c122e83586deaeceea50f5052a2f4 |
|
MD5 | 08042383411c8538b5fa157e7588b4bc |
|
BLAKE2b-256 | 0248eff6c77fd274d909ae70c33d364203769ff7969a14c760f48e99d2ddaa20 |
Hashes for css_inline-0.5.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b806f2f4f73630ad49e4521a64ba8abf35215236f7ae024d82b430ddfd8b0b41 |
|
MD5 | 8521ea207e20cec032eaec28430ffda0 |
|
BLAKE2b-256 | 839e4ce6b0cd8fd6fff1b151a074f33ec58f0f71768404723a577fb3e767f732 |
Hashes for css_inline-0.5.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c53969d3c59e904659542f63db50d688b8809cbc5e785e0cc116f04450a70c36 |
|
MD5 | c0f6cca5b4297d73ac1e1d59e7d18776 |
|
BLAKE2b-256 | f9dc7fa84b55b1b98dc988000f181c88404e0e08e873f7b1b19b481fa0d3629e |
Hashes for css_inline-0.5.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35269fcb95fbc0cf10e909fe9527d8e35827c8baea38f63457b81cecdc13985f |
|
MD5 | e80623aafdd694c00fd66a0cc5bbfcbe |
|
BLAKE2b-256 | 5089ca061036942e5d4137466f26c92bebff15d97ea8dd6e9b7685802d7b9c21 |
Hashes for css_inline-0.5.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40d4e59d7b7dee297c971984b4eada81608ac26efee36bb3a0b264bf26b4379e |
|
MD5 | 73fc18913702785e043ca2867f3d8379 |
|
BLAKE2b-256 | 59d61e74502687f83b1f004a8acba7c0105472f6602bbffd84489e74f9ec86ed |
Hashes for css_inline-0.5.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8da714846c334e559e2a5faf15b8bd054cf4d277d073e98cf5586d1b161980fd |
|
MD5 | 2b5766745c60d0d4761a4def06852e95 |
|
BLAKE2b-256 | 68c49e45b0a62c4a744547374e1d35f111c059bbee4969384f21460f4fb7c287 |
Hashes for css_inline-0.5.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75c60fce499dcd3591627e735e71aed3483ebb0e599bfc937335435481fd2797 |
|
MD5 | 5749493aa6b5719f0a7ad3ae75ca807d |
|
BLAKE2b-256 | 125aed0931cbfdc2a26d0b4e97ebb11410fbe4c04d2d1596cae48018f14e4137 |
Hashes for css_inline-0.5.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18daf148dbe6939310c4001d2c331337fa7b1298a6e4baa638172030e8fd14c |
|
MD5 | 502cf5b687ed3603bb75f1aaaee7115f |
|
BLAKE2b-256 | 4eb119cd2d29ccdb8b23e565e71c658137f870b4fdacfbab4070e5e418c19485 |
Hashes for css_inline-0.5.0-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac49602ee6edaf56bb231df76b84a55e6dc2b5d6bf842f7b73d25fa6053a752f |
|
MD5 | 0ddbdc9ca268e752d0e5e001886dc358 |
|
BLAKE2b-256 | 150556e4709c8cffc10eed5515aca46a251539a39f0e9ead643521f8a0bb07b5 |
Hashes for css_inline-0.5.0-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 583d7bd1205849c9587decde3ae8f71f156e7b708a70035c6b7a6ed9a79557cc |
|
MD5 | 38e151c92210f34d2a8102a8bfa453ea |
|
BLAKE2b-256 | 20c6bf8bfaa8dbb982b5377b700204e8f121a1ccfaaa65bbe0d0c7dbdc7206d3 |