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.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 781b7948e38a1fd5417953213ac1242cb46cfa706ec997a4d99fcaef60d01a5e |
|
MD5 | a0f7f4cb861a1b3dee08b392b84e84ad |
|
BLAKE2b-256 | 4afae421aded71b90bea507212db2e59f32887b8633a7cd8980d47abb1dbee70 |
Hashes for css_inline-0.6.2-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5277dce5134809679e185f29708fc8989fa8162eebbd923bbc787ab368b04d01 |
|
MD5 | 5976ffdd778a7fe53d5c2ed341271511 |
|
BLAKE2b-256 | b491bb366fa99da29ecb0ea026e2e19b5c860787feab2b2f0b77626255003cde |
Hashes for css_inline-0.6.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19f857781719fb3c0425184d28c9fd7e7838bb6d36bd2935f2ae95d6644621d5 |
|
MD5 | fec27e5ab1193be1ac8a3b3a2c6dfcb7 |
|
BLAKE2b-256 | a1e691cab2f3848ade132e1908dc0142f040ab6912dd7549b631fea98fc65233 |
Hashes for css_inline-0.6.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f07fe8c31a3c36619ae979dc96a9634639a8699d7d3e4ebd72eeb5e00cfe7c4 |
|
MD5 | 4e557e18f7c86522e3f18e9444594d48 |
|
BLAKE2b-256 | 83d2fbade17331dba7304f89a0efcde8123fc9924dd35119a4ef51f5895ceb9b |
Hashes for css_inline-0.6.2-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d37a28d8208ce5e71066c889d129aef74232ba955bded2d02ee51a9217b8ff43 |
|
MD5 | 987adddeaa55994f3c8269d72242cb5c |
|
BLAKE2b-256 | cd191287e3cde8d9a5f6ca50e36a95044390ee13a51e5b065b895310cda19912 |
Hashes for css_inline-0.6.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77ff2c60367ecba6d4d524116cafb702a39979a4f3314e795167c2443f708c97 |
|
MD5 | 29d9d25e86b43be5cdc5403cb65d921b |
|
BLAKE2b-256 | 43cc42a1b53ff29878429f1adfdc62ef1f3add8659292179d250c040962147dc |
Hashes for css_inline-0.6.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 905eb34337f1976fa41d0825c8450db9ce2611320c7ce058086c3269487c08eb |
|
MD5 | cbf463b06b5d22f095f1f801b86adea9 |
|
BLAKE2b-256 | 90b2b0463c5ca6e29f14e35d08cbc87a5f6b35233138c35263bd583ddc36d7da |
Hashes for css_inline-0.6.2-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b9388410eb082f4179a0a6bf5077d28148690756869e7b14e63f8c2262446f3 |
|
MD5 | 0d0791eff8a670655deb12f1d469fd8d |
|
BLAKE2b-256 | a0078ea1c02a29e24765646cd1e9cde214ef88eb45a2615d798dc72c9eafe1db |
Hashes for css_inline-0.6.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 018f626fd05d38c37f54dbdc183ae1a88e9f2d208100e80e0a3b4a3bc98bada9 |
|
MD5 | dd35a365feed7edaa859c470696b4c1a |
|
BLAKE2b-256 | 912e0eeb7e3f2b8090bd41d2a4fa93543080242b41cc23081f6a25f7589af5bb |
Hashes for css_inline-0.6.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeacfdc774744de93ea2a8f064ff9a8aa0ba725d5f252cc1360263b09998ce13 |
|
MD5 | 816a70787aa7849714751d78c1199ff7 |
|
BLAKE2b-256 | 78547081271acb5577bc3b9d201ec33da57a03f23da8ea2e206365ab650efbf1 |
Hashes for css_inline-0.6.2-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbe2557533e5e02c2720ba4c71e7b3f58d12db2385ee305bdeb3aeb7681284f4 |
|
MD5 | fac9d4151912359a1139e23e9abf9d60 |
|
BLAKE2b-256 | 63e9e9bcbdae7a3f7183ca1daac3e285aaed71f8082096c83bc28c63f5262493 |
Hashes for css_inline-0.6.2-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78140e4e3565a09c6f30269abe6a6eb50deddadd273c02d722eaf4184c38500b |
|
MD5 | f11a8d670e49200e3457b963c855f792 |
|
BLAKE2b-256 | 33b469dc6c619cdc1c171ea01bebe7fdd737fbb725ec76ae2c6ceecbf73e8e63 |
Hashes for css_inline-0.6.2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66988a30be940f49cac7f1e11edb6a85a9daf43277966fce6fa85b7b74ae2a35 |
|
MD5 | a8d743e28cafbdbc347041e2c4c603f7 |
|
BLAKE2b-256 | 367352f906d7e2d7fc14b7cd6fd550ed67e11ba2f83fff19ee76cb2b8e16bc0e |
Hashes for css_inline-0.6.2-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 151b844ea2e15e76518363c07247cc18c2a92eab61a92b240215e23e331cd952 |
|
MD5 | 34eaf37c2295e25a809e9ebc005d1b18 |
|
BLAKE2b-256 | cf7efcb25141fb3403bcb145346ad2edadc1c6d0e4ed1e6cf0bb760867f18493 |
Hashes for css_inline-0.6.2-cp35-cp35m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ca35ef95c57f13b257e3192584c119a591fc8cc4c1514f135325ff89e7e9bee |
|
MD5 | aa6cc4378f04d0e3c63c1f5e5b9dbc3d |
|
BLAKE2b-256 | 3fbdcdff6fbc9b6adc4ecc8fb012a4501ed1bbec8bec114a12cd77dd591d9ff8 |