Skip to main content

Tool for filtering unused CSS.

Project description

filtercss

filtercss lets you filter unused rules from CSS files, like https://purgecss.com/ but in Python.

Installation

pip install filtercss

Example

Filtering is simple, just use filter_css.

from filtercss import filter_css

css = """
.test1, .test3 {
    color: red;
}
.test2 {
    color: blue;
}
"""

html = """
<a class="test1 some-other-cls">test</a>
"""

res_css = filter_css(css, html)
assert "test1" in res_css
assert "test2" not in res_css

Limitations

filtercss uses tinycss2. Also filtercss will not be able to anticipate what DOM elements might be inserted by any JavaScript and thus will happily filter out the unused CSS rules they might want to use. filtercss uses BeautifulSoup4 to parse HTML and to detect whether a CSS selector in a rule matches against a given file. However, BeautifulSoup4 might not support all of the CSS selectors, in which case filtercss is conservative and includes the given CSS rule. filtercss is also not optimal in that it includes a full CSS rule if any of its selectors matches and it does not filter out unmatched selectors from the rule. Note that this may change in the future.

License

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

filtercss-0.0.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

filtercss-0.0.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file filtercss-0.0.2.tar.gz.

File metadata

  • Download URL: filtercss-0.0.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for filtercss-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7e71fc38f64b9707cb746fc7d9305bc9e167f10ecd9340374ba4347ea09ee41f
MD5 dab38791b07e8ee013a53b3bdb24416c
BLAKE2b-256 a83fe169a935ba32e41842f779accb2c8c70576b5dbbe1d46ec836e3f2ce5384

See more details on using hashes here.

File details

Details for the file filtercss-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: filtercss-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for filtercss-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd72e5a53a81bcb720d1b6d22d34896f2f2c637457bf746b5bbd7c4bece0cf1a
MD5 f3f6997603ab6f625ba84ba61688fa24
BLAKE2b-256 8c9f102a8721818af3de3081ec6aa3216f807b120602ebbd321f75ddbf374850

See more details on using hashes here.

Supported by

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