Registry / serialization / csscompressor

csscompressor

JSON →
library0.9.5pypypi✓ verified 23d ago

csscompressor is a Python port of the YUI CSS Compressor, designed to minify CSS code by removing unnecessary whitespace, comments, and optimizing various CSS properties. It aims to be an almost exact port, passing all original YUI unittests. The current version, 0.9.5, was last released on November 26, 2017, indicating an infrequent release cadence.

pip install csscompressor
INSTALL
IMPORT
SIG · CSSCOMPRESSOR
C
csscompressor
serializationpythonv0.9.5
Install
2.4s avg
Import
17ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.018s · 20.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.016s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compress
from csscompressor import compress

Compress a CSS string by importing the `compress` function and passing the raw CSS code to it.

from csscompressor import compress css_input = ''' your css { /* a comment */ content: "!"; margin-left: 0px; color: #AABBCC; } ''' compressed_css = compress(css_input) print(compressed_css) # Expected output: 'your css{content:"!";margin-left:0;color:#ABC}'
Debug
Known issues
gotchaThe library's last release was in November 2017. This suggests it is no longer actively maintained, which could mean a lack of updates for newer CSS features, unaddressed bugs, or limited community support.
fix
Consider evaluating alternative, more actively maintained CSS minification libraries if up-to-date CSS standard support and ongoing bug fixes are critical. For basic compression, it may still be sufficient.
affects: <=0.9.5
gotchaKnown issues exist regarding incorrect whitespace removal in specific CSS contexts (e.g., with 'px' and '+' in `max` or `calc` functions), 'mysterious duplicates,' and improper whitespace handling in SVG. This can lead to malformed or non-functional CSS after compression.
fix
Thoroughly test compressed CSS output, especially for complex or modern CSS syntax. Manually inspect the output for any visual regressions or parsing errors in target browsers. Report specific issues to the GitHub repository if not already documented.
affects: 0.9.5
gotchaBeing a port of YUI CSS Compressor, the library's compression algorithms might not be as aggressive or as intelligent as more modern, actively developed CSS minifiers, potentially resulting in larger output files or less optimal compression for contemporary CSS patterns.
fix
Compare the compression ratio and output quality against other Python CSS minifiers (e.g., `rcssmin` which Django Compressor now uses) if maximum file size reduction is a primary goal. Benchmarking may be necessary for critical performance applications.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'csscompressor'
The `csscompressor` package is not installed in the Python environment, or the Python interpreter cannot find it.
fix
Install the package using pip: `pip install csscompressor`
NameError: name 'xrange' is not defined
This error occurs when running `csscompressor` code (or an older version of the library's internals) with Python 3, as `xrange` was a Python 2 built-in function that was replaced by `range` in Python 3.
fix
Ensure you are using a Python 3 compatible version of the library. If the issue persists with the latest version (0.9.5), it indicates an internal incompatibility or an attempt to use Python 2 specific code. The library states compatibility with Python 2.7 and 3.3+, so updating your `csscompressor` version via `pip install --upgrade csscompressor` might resolve it, or manually replace `xrange` with `range` in a local copy if it's within your own project's older helper code.
AttributeError: 'NoneType' object has no attribute 'BaseStorageFinder'
This specific error appeared in a related library (`django-compressor`) when `compressor.utils.staticfiles` had a namespace issue, leading to a failed import of `staticfiles.conf` due to `BaseStorageFinder` not being found. While not directly from `csscompressor`, it indicates potential import or compatibility issues when `csscompressor` is used within larger frameworks, especially with conflicting or outdated dependencies.
fix
This is often a compatibility issue between `django-compressor` and `Django`'s `staticfiles`. Ensure that `django-compressor` and Django are compatible versions. If `csscompressor` is a dependency of `django-compressor`, check if updating `django-compressor` (and its dependencies, including `csscompressor`) resolves the conflict.
AttributeError: 'AttributeValueList' object has no attribute 'lower'
This error arises from an incompatibility with newer versions of `BeautifulSoup4` (bs4), where the `rel` attribute of an HTML element, which was previously a string, became an `AttributeValueList` object that does not have a `.lower()` method. This occurs when `csscompressor` (or a library like `django-compressor` that uses it) parses HTML with an updated `bs4` version.
fix
Pin your `BeautifulSoup4` dependency to an older, compatible version (e.g., `beautifulsoup4==4.12.3`) or check for a newer version of `csscompressor` (or `django-compressor`) that has addressed this compatibility break.
Upgrade
Version history
0.9.5latest on PyPI · released Nov 26, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
csscompressor — pip install csscompressor · libregistry