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.2.0 - 24.47 us
premailer 3.7.0 - 345.47 us (x14.11)
inlinestyler 0.2.4 - 2.47 ms (x101.03)
pynliner 0.8.0 - 2.82 ms (x115.53)
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.2.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.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a1f46402a51a5ec46012666c3590cf2b494755f12a8b5e97457385dd60181fc |
|
MD5 | 2cbfbb9fc8a4d5c48c574807c3b5e751 |
|
BLAKE2b-256 | f7dda3e7dcf8589c25425f1e54051f72848874b7e1c9984ab3145d8d0d71e967 |
Hashes for css_inline-0.2.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87d41c2a3c1f7cdb26f4b9e33396b468a430437ce98213b16e00aabc56250044 |
|
MD5 | 40bbfc9190b7956f753ed016da993622 |
|
BLAKE2b-256 | bd713981db1a6591f767f59ef95f3944824202e646b9fbadc84e6337d7057ad5 |
Hashes for css_inline-0.2.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a49a8b9cafe596a84ffd4276c190f3d9a6fcc7fc9fbd3daf487e8732444e3e37 |
|
MD5 | 052d34bc76afc9f4a5d059beff67f906 |
|
BLAKE2b-256 | befcec7233927d4e7613fa07e51d5c6acaee6ec1ec52976bb94e08371788b2a0 |
Hashes for css_inline-0.2.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da2146d10013b8968b374e80551ae069b83bbeab29a8a80d3067a217b0205908 |
|
MD5 | 437cef6abaf73ee5b787667719e0a5a0 |
|
BLAKE2b-256 | 65f6b30d480d93a92864526a95d84b064ca271a8c9b59c9f58dc951f95fdb889 |
Hashes for css_inline-0.2.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6af176ba5e51c360821375a7a274f01b8e3bc9220d577b4665f2f3b51b2acb8 |
|
MD5 | c5ae31149d20ff3293fdc7b1125af2fb |
|
BLAKE2b-256 | 489af2153e8b08f0230d6c4648d48f1e177ffbc4076ff028f78391ce69a6da77 |
Hashes for css_inline-0.2.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 968b4ee534841def59388c90a6973a9f537e22677b7277984aa5968d001b9c22 |
|
MD5 | 99b03cc1104df4d20a344286356b8659 |
|
BLAKE2b-256 | 5047588e905692c4bf001746727fa3cfdf09e9f9a29f36026b8bc6b470830d7c |
Hashes for css_inline-0.2.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d6c2c457e594145c7f47f37c84e3d1526f561e3ccfafc3342efb69ca27f345c |
|
MD5 | eb3df2438a78004a685fc86a38dfe31b |
|
BLAKE2b-256 | 8f73b77f1e293249a23847531bccf9354e7090b40c8d0c298f0ff226f8d2510c |
Hashes for css_inline-0.2.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8dbb417586b2cb9fbbed1568753e325a5ee61217612e9e119260445ddae745b |
|
MD5 | ccafc986f41896e754954dee8d82dfdf |
|
BLAKE2b-256 | 74f3e2b798b748175e9f1b099511605932fb729cba44e8274585cc8615c30d0f |
Hashes for css_inline-0.2.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9cbaa61974caf306546573740c1de2236d54e6ac235d598b5e9014db892b3b5 |
|
MD5 | aea4de0e68fd11f3d08e40cd69b6f948 |
|
BLAKE2b-256 | 8a1583c5e61425433ba21162069170d1201ae8e6604c7ee7f9b92800faa75a1b |
Hashes for css_inline-0.2.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2441cd4b91abe32a4dc22ca20c07f3f8f06688411a21d2bd2a31e63db19c3346 |
|
MD5 | 48def89aaec9900881485351baa011ba |
|
BLAKE2b-256 | 5523ca75920cac2bcb66bf231888356bb7ef6ade2627cc36c942130d105e2f0d |
Hashes for css_inline-0.2.0-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de12b26501faeea48e24331fcbcf6fc4fbfcc8bf67d7b6f5c05ff6358f72784b |
|
MD5 | 6ac3d513599fb7a2a827158855839611 |
|
BLAKE2b-256 | a342d4bbc5569a2f656d7b0c8fc9f945ab04f8d3fa6ab314231e9bd655c57cc5 |
Hashes for css_inline-0.2.0-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c31f6a72a925e0f9d60ada56219d9f2ef3c7a96f8db29b905633109fdd9bef6 |
|
MD5 | a3adb8b4666cfeac09b0f5f1327c18df |
|
BLAKE2b-256 | f4033cba264851151b7a364d1ea1b7e05cc86af1da73a5c08a6c807c609f36cb |