Fast CSS inlining written in Rust
Project description
Fast CSS inlining for Python implemented in Rust.
Features:
Removing style tags after inlining;
… 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, h2 { color:blue; }
strong { text-decoration:none }
p { font-size:2px }
p.footer { font-size: 1px}
</style>
</head>
<body>
<h1>Big Text</h1>
<p>
<strong>Solid</strong>
</p>
<p class="footer">Foot notes</p>
</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 ~12-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.1.0 - 24.82 us
premailer 3.7.0 - 356.59 us (x14.37)
inlinestyler 0.2.4 - 2.62 ms (x105.82)
pynliner 0.8.0 - 3.03 ms (x122.44)
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.1.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.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1df30521080747f87cf694be52255623dc75334a8ef737a223ca4a48021e8f54 |
|
MD5 | f03aa2db750abd72462dd7ba6bc089d7 |
|
BLAKE2b-256 | 187f43d0e042dbd651aed3601374cb1b571b8950a9cc379b3b3541dccb398322 |
Hashes for css_inline-0.1.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c65a98686f5a2f0ed15dab00fc8523dc38509ef9ee675bc06fb92eff47728b0a |
|
MD5 | 68475050f5c413cc9b0e9fe8d529c799 |
|
BLAKE2b-256 | 88b35c617cf69d2cebd4e3672fc7e97a1b6606f0b97a42890529ddc95bf4cefc |
Hashes for css_inline-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f899c041a077b6f3229d4d64d992949e18310935b215b48c093eb6379be812f |
|
MD5 | c8face41b8a4dba75343f9ea3a38ae5c |
|
BLAKE2b-256 | cf5dd2cc84eee6596853a6deca54daaa3ead5cbbdc17e1566654372ac5aae2dc |
Hashes for css_inline-0.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0394ae140e6923366d59e54efc7ee57ecd8f7597c4455a6e910c589e0f09cf90 |
|
MD5 | faaa183719a611e46e6d14a2d8f05cf4 |
|
BLAKE2b-256 | e02a8d577035b2d8378032cb6466725a1bbe9290e1e27e7c059b78a44ab18c37 |
Hashes for css_inline-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a105295f4894e34d5a78817f7a19f7242866c3fe54fe2339f51e8ba52917c1c3 |
|
MD5 | 3861115735b0924bb1a008c16911a44a |
|
BLAKE2b-256 | bb6e6be3d28ee169863ed4c774cbb766d4cff5b2ac540e6f6e7d9d85b3934f71 |
Hashes for css_inline-0.1.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6a3b1616338fff7052a41fbec736d103c63cf1a732b1886ae7c5dea78901a79 |
|
MD5 | 31f0927210a0b919b4c60042a0c5f2f4 |
|
BLAKE2b-256 | 932414326de0abc12c03d98a11d44235ff0e6617903b7120359e3ac06b6c7a2f |
Hashes for css_inline-0.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abf95c19f8e37e01e83befb99e9b821f1a8184cd0b0d8ffe5940f88615f1bdfa |
|
MD5 | a0416f31fce5c9a1c08cc67834fa3e4a |
|
BLAKE2b-256 | f0aad6c2454819358e5fb6dcd8af55aa6417779c703de8fe151b27013eb1e1b6 |
Hashes for css_inline-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7410d867bca72e09bc0badd20bfcdd2fe4f906de612aa709c9aab076a02a31cf |
|
MD5 | 692e5e9d978f79656fbeccc00b640de4 |
|
BLAKE2b-256 | ec9089786005ecbf0f405d9468f5003542890efbc9f084997a820a49f6409624 |
Hashes for css_inline-0.1.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81cc60ad3e093b8dfe848aefe2ff5f07ce408c879c899cbffe06914bd4d45ab8 |
|
MD5 | ba13638168e5a2bca2437d8a2e072a55 |
|
BLAKE2b-256 | 320508d3af6e290275e0263607bacb9d8857ae2598c6a094d176ec56b5e05990 |
Hashes for css_inline-0.1.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa3020c110e3d43d375783e872547dfc3a23c7c0285842b24ba617570adc62d0 |
|
MD5 | e1c53592aaf8a62f1b9a880fa93c25df |
|
BLAKE2b-256 | ce1b999b21fb0bef35a9e74b3f9644ba463b36521981782eb5411b97e37e36b7 |
Hashes for css_inline-0.1.0-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c57ea7f44c0b503501012a67c4177d3e5ba8a503d65985f0b95c21a2e1bd1e7a |
|
MD5 | d871a44afb6623bf4e6843b98f270d7c |
|
BLAKE2b-256 | d79d3cf6c47fb2a629ddc8b95fdab703e110e6f07a136e534924500dbedfdc46 |
Hashes for css_inline-0.1.0-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48daba101e7d74b2685c0069af0c90b7da534f370f3f35523f2f2bcb3920e091 |
|
MD5 | 75390fdb3dd57de48c3aec95ad69a6d4 |
|
BLAKE2b-256 | ff3a05d3727b6a5daec7498da339908eeac047d73b6d110b6bb80dd680241c80 |