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);
… 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 { 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 ~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.3.0 - 24.38 us
premailer 3.7.0 - 339.03 us (x13.9)
inlinestyler 0.2.4 - 2.44 ms (x100.46)
pynliner 0.8.0 - 2.79 ms (x114.66)
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.3.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.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7af3c0ffda5c5e249fa9515a86537592a111e80ec750ab4b0d1aea2145f4b593 |
|
MD5 | 568e039414e4167c93d8dc6e333b407f |
|
BLAKE2b-256 | ac5509cfeb1e13353c86e8202b2fe859bb4ceaea598932c79aac528633699063 |
Hashes for css_inline-0.3.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36fe6824f2723ab39e58f3632b2c06acc739200e327295ac1adfabf31c16c420 |
|
MD5 | 3f6c6e5813cb12aa191694b5c405a1f9 |
|
BLAKE2b-256 | f09455240e7672d1e0c240ad79fa0cfa633a4326cb869a3f7fb734b1ce8ee03e |
Hashes for css_inline-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aaf31e1b6cfc710ce79e39a13fc78d2ef7d091558e7c87f22fa2dc2159ebd81 |
|
MD5 | 51b25c32144bc6420195baaa2faff441 |
|
BLAKE2b-256 | e263bfc4136e1010ce9b4612ad81e634757f9dd299fffc3dfef91cdda008173d |
Hashes for css_inline-0.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffec3f751d141d14265a509512c7190c29d0a0f1e44bf89ec4c7a7d25a28561a |
|
MD5 | b08dbc4e8dff26a3125cc864f9b01ee8 |
|
BLAKE2b-256 | 79e510928f4c45ec24987918c7138aa70e13061f564b70df0b530b7c0d1b7f50 |
Hashes for css_inline-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7cdc559a68b55ab8f12db23926405704583f7dad71b5d310270bef4fb243a9a |
|
MD5 | 74a85259f20f90d082d5fd56ee0a5a3b |
|
BLAKE2b-256 | 285ec46a9daea311caf233e7579c41379415a81fd2b3f35348ae9c330a80250a |
Hashes for css_inline-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a439827c2d899b0e5330f599eddeaaa48a55dc4e327cad4805df542a4b7db90a |
|
MD5 | 5ac06a996ec8108d538f95eb9818d95e |
|
BLAKE2b-256 | 5ddbe660a2f3164d425fe4715e0098c7b5ff890b011384d1bb65b2f7f233afec |
Hashes for css_inline-0.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa91e7f9d935702c1cf16c32e3f123165f19cbabd8251ce77087f73ac0bec3d4 |
|
MD5 | 5725d1be34abc7688f7df75185d1b605 |
|
BLAKE2b-256 | 355b3e65d9e777489ade00c7ad39f9101965433adfd333ef95b90c6d065c69a6 |
Hashes for css_inline-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ddd182a862047fc5910d6fa7221b2a0122158df22d7b47dc44eb54f6649d701 |
|
MD5 | a3a258d590b78a00add5533e9ec610b2 |
|
BLAKE2b-256 | 939369d7279dde6ba94880dc73d430dc8cdf76faed0d66336bc94e4c561d3b00 |
Hashes for css_inline-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8fa41cc34aee8c4db3e523ddc46f8169a316ec3e168245d7e9b248bec563acc |
|
MD5 | 2a84cdac8e6d7f364ea1c950ce2c017a |
|
BLAKE2b-256 | 72fa1b0f7fdc9c772318760f882dd44128c4711b721487e0dfb93f69155a12e7 |
Hashes for css_inline-0.3.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abd03adacb536433cf17118fa8931d058f0a622613374d04ba9304aba15760f6 |
|
MD5 | c5a7aad1f314a06a3878efdb4e84aaf5 |
|
BLAKE2b-256 | 184a795d4c39dc45e899a5aadf0e13509f1d09374efd27a19553d9af932e41ab |
Hashes for css_inline-0.3.0-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e309b918a736015697bccfabfc561e6dc34d3de1f19e3151bbe70ca21d4ef9f0 |
|
MD5 | 8961e2bcc112a2cd522d4bf984967605 |
|
BLAKE2b-256 | a604e1dee8ef691de0dd93bf5bbe8d42bcff8825337a5e1a76451c6b7de40632 |
Hashes for css_inline-0.3.0-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04113b04282bda92543c92c1d2d4cde186212e841d5fa70ff918098d0208dc5f |
|
MD5 | 6ed30dda943b122fb2513ba4f90faee6 |
|
BLAKE2b-256 | a42bb07949df7a9821ba021c2a84c9f7b3e499723ddcb6857d8e16a733ab1922 |