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.6.0 - 23.01 us
premailer 3.7.0 - 340.89 us (x14.81)
inlinestyler 0.2.4 - 2.44 ms (x106.35)
pynliner 0.8.0 - 2.78 ms (x121.04)
And for a more realistic email:
css_inline 0.6.0 - 483.3 us
premailer 3.7.0 - 3.38 ms (x7)
inlinestyler 0.2.4 - 64.41 ms (x133.28)
pynliner 0.8.0 - 93.11 ms (x192.65)
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.5, 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.6.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73422507417862a27f7ea7c02b8cd951aa5674f629cc14889381e1ac21485f9a |
|
MD5 | d8a06e64284b0f33db3b26252b0713b8 |
|
BLAKE2b-256 | cf24881bbd2b49987c24b52f9b7bd05eb566a182e95b59055071e88891d4a76a |
Hashes for css_inline-0.6.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13a71d7a9b0709a3682483e971099d4b0ccec3dce962b30d207bd6d7c7596911 |
|
MD5 | 576b3046e9c4b6b2698d5ea077be955e |
|
BLAKE2b-256 | 34fb84a8a4a3160a2dfa76a10a323d73bb8cb2e59243c3a270e44e265c85a28e |
Hashes for css_inline-0.6.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 964010a273b388667bda9ee8f6ebcfabe04345a1db9c25f178a40cbae915f7c6 |
|
MD5 | ea439435bd205a1b5659747a40d5e69c |
|
BLAKE2b-256 | fec2abb0c24544681c5fb5b3e955c6acc42882250c8ed6d914c020e467330747 |
Hashes for css_inline-0.6.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb57aa1f797ccbb10d971f1de93bf6c7914564e6e58c7487ebd08b915b6a8460 |
|
MD5 | c372f54b4b4cb2eaba19082467b59a22 |
|
BLAKE2b-256 | eec56ba65d9b50d698fd412fe4717b58ceeea7cfac9e59ea05af657139409fbb |
Hashes for css_inline-0.6.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90bc7ff0c3c08176cbd8266421066171a1b58c844ff8ba06c99bf44820c49b56 |
|
MD5 | b5243a1c899b54c89a773cd073cf7797 |
|
BLAKE2b-256 | b1f7851d23f30a92eb99237b2fb8174c5e170fa780e6381c7e374a06cf435e50 |
Hashes for css_inline-0.6.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae892002d955e49895be996c035056441558389ea0515436d900ca2837cd9876 |
|
MD5 | 66f8eab8a33a0d725f65229843f5ae8f |
|
BLAKE2b-256 | e60c82ed045faa34c2b02b5df88232f1c984dfbb88dcd59e52376ea059b6b6f1 |
Hashes for css_inline-0.6.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f78ffca3f0eab8177bfac9f2056a174fd31c67450973fd4ac1e8569a9e43c576 |
|
MD5 | ca479d08ef865efe937e06dd9c6b927d |
|
BLAKE2b-256 | 6fa388fd029be4faf4ee32f620f0856110cf71a0964f6e341edd9c9ecae5a924 |
Hashes for css_inline-0.6.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ae3efe66d10d40cc6235e3cad9a81d651c02479c1876f8e42dba170e8c5fc81 |
|
MD5 | db90fd6b4cf3975eaecf68d8d9ee9860 |
|
BLAKE2b-256 | 723a0507f9b31eba90b2f09000c5ac31b83227df208b7c723c112ce7d8145dc3 |
Hashes for css_inline-0.6.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41891898ec9e016b2cb965b7554b7b99ef17aba4c7855c31ae6c55e7952f2520 |
|
MD5 | 9b655c105e6c5884d05c85c4d8e356bf |
|
BLAKE2b-256 | 026d586678a20c00992b2b3263be0af6d72156655e108db6700260fd8cd10336 |
Hashes for css_inline-0.6.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b5850832bb9fdc1c37e02d470da2913079cbb3c70537f47a020dabfae9ae7d |
|
MD5 | 588804df789d7abd247f7f108d9cd799 |
|
BLAKE2b-256 | d07e3e2f17d3167169954eeb3cd0ad13d5b4d6c8bb9a12a755a76dbcfd861d5d |
Hashes for css_inline-0.6.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 678a557b4918dd32c51cfe5b00f4ac601576b9ace549b5f6c30e480d4113a3c2 |
|
MD5 | f2e355db68f3968f2fa50bad73e7bf73 |
|
BLAKE2b-256 | ff608672f482cb1051188ffb7429987128a97c1868bd8da17205478213e1c388 |
Hashes for css_inline-0.6.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cba5fe8865a54a4af5ab6cc5ee0e8d05e9f35d46c6e31223a0b47d4485b6f0fd |
|
MD5 | d23909f9592b175cdb9fc8decdc6a048 |
|
BLAKE2b-256 | 8c0c9d96fc0722c50d2899f50ed93d63bd77e4719027f18ce43f2ea8e5891857 |
Hashes for css_inline-0.6.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1126e5ec4946b23f952f1bb93a54a8d4a9949802f71bd8538227633c63dbee6 |
|
MD5 | 346331049c3a8bd7924e509dafd1af93 |
|
BLAKE2b-256 | 576fc56c0ecda1515227424bf283157e1815b512f769cf67cea9fe8eaf86fabb |
Hashes for css_inline-0.6.1-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8344da7a7c0c2ce6d5be19ebfe057215c68bd86e06c899eb46932517b00d63f1 |
|
MD5 | 42d8ce1b97a350ac859f716717122066 |
|
BLAKE2b-256 | a0d6b270abfbb5f8280f537cc462bb071e1e556ad896624c23a8db47c5a4d474 |
Hashes for css_inline-0.6.1-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c28ac92561b3d75fccfedce393952a4a80f8b0451ec0a078bbb51ac2a9d2280 |
|
MD5 | c0f131ba78ec2ee77eaeb0ca8d371740 |
|
BLAKE2b-256 | 2413536b20dcdd57bf29b63d595510b429207490d176a7ba023085ad10ca5243 |