CSS Compressor
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.
Warnings
- gotcha The 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.
- gotcha Known 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.
- gotcha Being 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.
Install
-
pip install csscompressor
Imports
- compress
from csscompressor import compress
Quickstart
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}'