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 ~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.3.2 - 23.31 us
premailer 3.7.0 - 335 us (x14.37)
inlinestyler 0.2.4 - 2.48 ms (x106.64)
pynliner 0.8.0 - 2.82 ms (x121.27)
And for a more realistic email:
css_inline 0.3.2 - 482.79 us
premailer 3.7.0 - 3.38 ms (x7)
inlinestyler 0.2.4 - 62.64 ms (x129.75)
pynliner 0.8.0 - 92.18 ms (x190.94)
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.2) 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
File details
Details for the file css_inline-0.3.2.tar.gz
.
File metadata
- Download URL: css_inline-0.3.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c924b096cc3ee8d4b63818ca212bc05e0f0f2e42fda614475ec22f47b08c4b2e |
|
MD5 | d725a5b0a2b121af0399d490586e1a4b |
|
BLAKE2b-256 | 1d6d9b52cbbbcc711decd77f1269a08352d7b0de9b8982f17f7d35203e8e64e7 |
File details
Details for the file css_inline-0.3.2-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 864.9 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 898dd336be54a62f4b93344de449e43dd6cf9ae48c892ff68d2d5f86b0cb1023 |
|
MD5 | a512725a822c2212ade5817b2ca88edf |
|
BLAKE2b-256 | 5d2cd244f3daa4fae4ac4750a9f12efd1ed1c6d5ad277b8a5a9432eed549d0b6 |
File details
Details for the file css_inline-0.3.2-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a8e7c94199b4161644e041fe09090d764caefda29717e154a70c5284078595e |
|
MD5 | d1da72f85c6d327b8058c70c5509afd6 |
|
BLAKE2b-256 | bef0a9d949f55a181327e00abe4b41a48ffb7c9cb8c86a6f7f3d65f5f3e430ba |
File details
Details for the file css_inline-0.3.2-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 908.9 kB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b40f37b41f3ddd137fd86bff5024d80708f9544336ca26160283e8251c18f433 |
|
MD5 | 8590648910b68bacf045cee851718834 |
|
BLAKE2b-256 | e9e43d1492abe9ad24b85fde34a671a5fb7cd10829732fa5ee6f19d4f016424d |
File details
Details for the file css_inline-0.3.2-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 864.9 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83e399be50bbf076028a4c76073ad4c2ba843478bdfbf4acc898b2339609b62f |
|
MD5 | 6351ec4af7aec95edd07cb47128ca2d7 |
|
BLAKE2b-256 | 9c805ec0f9a2fa8b2596f22484befc0a10fa96e760f22a6f24823a41ae2f78d8 |
File details
Details for the file css_inline-0.3.2-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af3fdd63b9e82e266026a5f050df35ff2f78d261a057db2611857536f6cdd525 |
|
MD5 | b43acbddcb32ffd3b11aa4a2572e037f |
|
BLAKE2b-256 | 0d928a7f99be87ea5d393b11294a231f76f643d1c71d85c27622e448e4377213 |
File details
Details for the file css_inline-0.3.2-cp37-cp37m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp37-cp37m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 908.8 kB
- Tags: CPython 3.7m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60d18f557c4c838c971c7abb9834b43dd061f34fdfad54ad2b2e7c561d7c3cf9 |
|
MD5 | d9067a27fe01499b87b55b1f64ee588a |
|
BLAKE2b-256 | 7fe96b75d90aabf452645958989e9ea81d7da3647f1dd62e3ffc94147958654a |
File details
Details for the file css_inline-0.3.2-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 865.0 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168370d2f13452a2862d3c677f52ba87d25ee41e7ac575afc142c05f1b1f41f8 |
|
MD5 | 17d8f5c459835db1d762c33fbcf29658 |
|
BLAKE2b-256 | 5d9be998b6dfb4da2c322d576e7821bdcba0d2e68cc241a16ad4b7577037fd9f |
File details
Details for the file css_inline-0.3.2-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54e17395d491aa12d1a876bf6bbc3eb0f2e774274e0ef9d9020192e1b82e3ccb |
|
MD5 | 0885d543a9efd5f67aa602d07360d40e |
|
BLAKE2b-256 | a3300c5d4804c4211e31a45b6e75c4d7321e8f9782515970d8004a0457892d6f |
File details
Details for the file css_inline-0.3.2-cp36-cp36m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp36-cp36m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 908.9 kB
- Tags: CPython 3.6m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aa6725dd746b8a0710657c74ff6b2c6dc578b010d58bee6a37a80858d089fe2 |
|
MD5 | 831f136ec4335e0568f79b698a07d266 |
|
BLAKE2b-256 | 4bc6aecc12629c3813b4b6c171219c5bdea34a31b563acf28b87e93772b3eb07 |
File details
Details for the file css_inline-0.3.2-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 865.0 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be1b5d70411b6ec0022632f715c6b4c23f835f9a3983fa86f10174412f5b2f47 |
|
MD5 | 222d6bf09aa49b9d2368856ea2fb89b3 |
|
BLAKE2b-256 | b2f879a11008543a6e3a9a738edbd3f1268a8d8182242e9a84a6aedefc7860f4 |
File details
Details for the file css_inline-0.3.2-cp35-cp35m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp35-cp35m-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fee074c0a622370f59ae35fcd87b2f7c4e8af95b5ffc9ce725a5dcaa2c7d335a |
|
MD5 | cc33bd4a9d46ee8e6c9df9ba2ed5ac60 |
|
BLAKE2b-256 | 83a472416af4e16792515e4f3428a424929ec0a7c57210222ac2312c3284e10d |
File details
Details for the file css_inline-0.3.2-cp35-cp35m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: css_inline-0.3.2-cp35-cp35m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 908.9 kB
- Tags: CPython 3.5m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41b4b7154dd694e5ed0fdf233c52d949febe71b961dd03d9d8b9fc87b37d98f7 |
|
MD5 | 3a2b14f3d841b1dee4e1bed19e3c187a |
|
BLAKE2b-256 | abbccc3dd03ca9508e8bbe3cbe0d1796dc97a02d636c6587b2a7546047bce5b3 |