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, 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.6.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20b95f7ebcce5a0d9c9f5c592c60ab8e03c531eb0b669625df62f011b366648d |
|
MD5 | 27599952747e8ecd42594ae99d6da2db |
|
BLAKE2b-256 | 4956f206f91d5cf198f73ff313eb393a9dbc07f3947afb1d2b0009c295a3f9ef |
Hashes for css_inline-0.6.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81d3b7bee7776a61b50fc34460db1915b5095693d1b8a57ec02b09455d92eebd |
|
MD5 | afd7c67e366a0eed7deb9c5213d3e637 |
|
BLAKE2b-256 | 87ea08d076f3b9e73e2bf9641f36e7f398d80ef653e8804bb075bb41e70b33eb |
Hashes for css_inline-0.6.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fed7f7f738cda18404fbeb99a70f8beb9681b8414e5b1556040024c7a3e5f8d |
|
MD5 | ed7256e2ad51ae9c41047c22c684be1b |
|
BLAKE2b-256 | 1c6eac5a2909f203de5a00ca8b4296d8e509f5d44181acff26ea4bf5ffc05c39 |
Hashes for css_inline-0.6.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b98544397d2953cdcf22c5a1188da66c3d59b58f4ac159c05d0eb1cac58f1382 |
|
MD5 | 2e6b64e6294c47eb1d249dfa6298094b |
|
BLAKE2b-256 | aef8f74f996a4776c07761a96d8df69e46be952b10160243cd812bca55bd74b5 |
Hashes for css_inline-0.6.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cc5db1826d61280003d21e05942529bafcaf72f31cc0da7605fd12cf137d101 |
|
MD5 | 56fcc7b56bfd8dc6e86d69ce41a48794 |
|
BLAKE2b-256 | 332d806da7cae3814da6a77ee99c5d01392eb7919bfc1e314158ac6e0760eadb |
Hashes for css_inline-0.6.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ff75eb27af3baadb8325beb00edc7b029eb58a58114f11e12c2e2d5a7616ae |
|
MD5 | 70bab29ce408717b7a9205331f3da380 |
|
BLAKE2b-256 | 6cecd28d089111bc221ffce6211cae005f9e35ec3943206f9d05c1577a5086b4 |
Hashes for css_inline-0.6.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6da8b9a474372081c93c52f40e69aac348310fd2d03fb1c5be2b4e6629e59cab |
|
MD5 | 4750e5134d73549eb0cb5e6412b1bbb3 |
|
BLAKE2b-256 | 98fa739738722f478a6d528aa8a43d8772846b98112779ab050727a5b49c6cc4 |
Hashes for css_inline-0.6.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18d9a67dee309519b35583ba495b8a394db864cdfe71b940a83305b12d79d2d5 |
|
MD5 | 8222801ad3d050d7f85e98874efd7b92 |
|
BLAKE2b-256 | 5528aba712f5b8d0287444dd0f5f9aeaff0d931be689fa7f766085c9ecf3e677 |
Hashes for css_inline-0.6.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2c9ea87574432f2a8fb72b9752dcc162ad163cbd8c03271d70bc0b625759f1 |
|
MD5 | 9e9dd198c196540ff3676226b2066422 |
|
BLAKE2b-256 | b09f8fbbf81b69cbf2a44df3c6517a9b8d7c764e95b6c79b95357b0384077ff7 |
Hashes for css_inline-0.6.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 063b5f8beac814db37979919c7861d55ad67ba155dc68ef8bfd64a712bbdac42 |
|
MD5 | 826e571b0609539a02c60e317f06e001 |
|
BLAKE2b-256 | 071346a2a80536f7edd4884e171a74b596a4eb901ffd9cabd1b69ebeb35211fe |
Hashes for css_inline-0.6.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8026c3cb1c16d1f2dc89cf2f29d58dc4e5159ab65cdbcb56e5f25b947474ed53 |
|
MD5 | f3d55444c9838054919dbd587613c277 |
|
BLAKE2b-256 | 54e7e5fb18c0502bb6ea7799498a1bb3bae9a02bd6d2374d24f91966d97a3235 |
Hashes for css_inline-0.6.0-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9def8c862b14a8fc6a5f3ffc67b4c0c062b309d7fbc9e01ec2ab728cd1786f4 |
|
MD5 | 36f955dd957f367a17b88b720fd6ebc8 |
|
BLAKE2b-256 | b2555bd084c695dea2ac766b5040ea13be5bcb7ef6241aceb52af70378e33283 |
Hashes for css_inline-0.6.0-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34f9fedf241e169775dce9a0cbf6342aadf9a8bc31b2ce863f038d593e91978d |
|
MD5 | 34df14721235a6ff423df304c9372097 |
|
BLAKE2b-256 | c53fce3ddd6bc60d7e62413453bce1c4e1ca92e7398741139371ede665eb8c77 |