Skip to main content

Fast CSS inlining written in Rust

Project description

Build Version Python versions License

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:

  • Inlined CSS is not minimized (#12)

  • class and id attributes are not removed (#13)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

css_inline-0.3.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distributions

css_inline-0.3.0-cp38-cp38-win_amd64.whl (852.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

css_inline-0.3.0-cp38-cp38-manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.8

css_inline-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl (904.3 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

css_inline-0.3.0-cp37-cp37m-win_amd64.whl (852.9 kB view details)

Uploaded CPython 3.7m Windows x86-64

css_inline-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.7m

css_inline-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl (904.3 kB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

css_inline-0.3.0-cp36-cp36m-win_amd64.whl (853.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

css_inline-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.6m

css_inline-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl (904.4 kB view details)

Uploaded CPython 3.6m macOS 10.15+ x86-64

css_inline-0.3.0-cp35-cp35m-win_amd64.whl (853.1 kB view details)

Uploaded CPython 3.5m Windows x86-64

css_inline-0.3.0-cp35-cp35m-manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.5m

css_inline-0.3.0-cp35-cp35m-macosx_10_15_x86_64.whl (904.4 kB view details)

Uploaded CPython 3.5m macOS 10.15+ x86-64

File details

Details for the file css_inline-0.3.0.tar.gz.

File metadata

  • Download URL: css_inline-0.3.0.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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0.tar.gz
Algorithm Hash digest
SHA256 504824aa00cc36b22a1cb5bd6b686ee4cb4f6157a5c9985c0ff009be74dd09f7
MD5 c3492dd477f36432176a9430de47d96b
BLAKE2b-256 fbfcf9c4f479e2944983f26097fc7209c3baccbdce92bd9ad1cedba84f96fda3

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 852.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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7af3c0ffda5c5e249fa9515a86537592a111e80ec750ab4b0d1aea2145f4b593
MD5 568e039414e4167c93d8dc6e333b407f
BLAKE2b-256 ac5509cfeb1e13353c86e8202b2fe859bb4ceaea598932c79aac528633699063

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 36fe6824f2723ab39e58f3632b2c06acc739200e327295ac1adfabf31c16c420
MD5 3f6c6e5813cb12aa191694b5c405a1f9
BLAKE2b-256 f09455240e7672d1e0c240ad79fa0cfa633a4326cb869a3f7fb734b1ce8ee03e

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 904.3 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.46.1 CPython/3.8.3

File hashes

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

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 852.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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ffec3f751d141d14265a509512c7190c29d0a0f1e44bf89ec4c7a7d25a28561a
MD5 b08dbc4e8dff26a3125cc864f9b01ee8
BLAKE2b-256 79e510928f4c45ec24987918c7138aa70e13061f564b70df0b530b7c0d1b7f50

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7cdc559a68b55ab8f12db23926405704583f7dad71b5d310270bef4fb243a9a
MD5 74a85259f20f90d082d5fd56ee0a5a3b
BLAKE2b-256 285ec46a9daea311caf233e7579c41379415a81fd2b3f35348ae9c330a80250a

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 904.3 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.46.1 CPython/3.8.3

File hashes

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

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 853.2 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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 fa91e7f9d935702c1cf16c32e3f123165f19cbabd8251ce77087f73ac0bec3d4
MD5 5725d1be34abc7688f7df75185d1b605
BLAKE2b-256 355b3e65d9e777489ade00c7ad39f9101965433adfd333ef95b90c6d065c69a6

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ddd182a862047fc5910d6fa7221b2a0122158df22d7b47dc44eb54f6649d701
MD5 a3a258d590b78a00add5533e9ec610b2
BLAKE2b-256 939369d7279dde6ba94880dc73d430dc8cdf76faed0d66336bc94e4c561d3b00

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 904.4 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.46.1 CPython/3.8.3

File hashes

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

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 853.1 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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 abd03adacb536433cf17118fa8931d058f0a622613374d04ba9304aba15760f6
MD5 c5a7aad1f314a06a3878efdb4e84aaf5
BLAKE2b-256 184a795d4c39dc45e899a5aadf0e13509f1d09374efd27a19553d9af932e41ab

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp35-cp35m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-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.46.1 CPython/3.8.3

File hashes

Hashes for css_inline-0.3.0-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e309b918a736015697bccfabfc561e6dc34d3de1f19e3151bbe70ca21d4ef9f0
MD5 8961e2bcc112a2cd522d4bf984967605
BLAKE2b-256 a604e1dee8ef691de0dd93bf5bbe8d42bcff8825337a5e1a76451c6b7de40632

See more details on using hashes here.

File details

Details for the file css_inline-0.3.0-cp35-cp35m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: css_inline-0.3.0-cp35-cp35m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 904.4 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.46.1 CPython/3.8.3

File hashes

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

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page