Registry / serialization / cssmin

cssmin

JSON →
library0.2.0pypypi✓ verified 86d ago

A Python port of the YUI CSS compression algorithm, providing minification for CSS files. The library is currently at version 0.2.0 and has seen minimal updates recently, suggesting a stable but slow release cadence. It aims to replicate the functionality of the original YUI Compressor for CSS.

pip install cssmin
INSTALL
IMPORT
SIG · CSSMIN
C
cssmin
serializationpythonv0.2.0
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

cssmin
import cssmin
The primary minification function is accessed via `cssmin.cssmin()` after importing the module.

This quickstart demonstrates how to import the `cssmin` library and use its `cssmin()` function to minify a string of CSS content. The output will show the minified CSS and its reduced size.

import cssmin css_content = """ body { font-family: Arial, sans-serif; color: #333; } h1 { margin-bottom: 10px; /* This is a comment */ padding: 5px; } """ minified_css = cssmin.cssmin(css_content) print("Original CSS size:", len(css_content), "bytes") print("Minified CSS size:", len(minified_css), "bytes") print("Minified CSS:\n", minified_css)
cssmin --version
Debug
Known issues
gotchaThe `cssmin` library is based on the YUI CSS compression algorithm, which was last updated in 2011. This means it may not fully support modern CSS features (e.g., custom properties/variables, `calc()`, newer pseudo-classes, grid/flexbox syntax) introduced after this period. Using it with complex, modern CSS might lead to incorrect minification, malformed output, or outright errors.
fix
For projects requiring support for modern CSS features and standards, consider more actively maintained CSS minifiers like `rcssmin`, `cssutils`, or external JavaScript-based tools such as PostCSS with `cssnano` or `clean-css`.
affects: all versions
gotchaThe `cssmin` library has not been actively maintained since 2021. While it remains stable for its intended purpose, this lack of active development means bug fixes for new edge cases, performance improvements, or support for future Python or CSS standard changes are unlikely.
fix
Evaluate alternatives such as `rcssmin` (which aims for higher performance and correctness for modern CSS), `cssutils`, or external frontend build tools if your project requires ongoing maintenance, active support, or cutting-edge features.
affects: all versions (0.2.0 and earlier)
gotchaThe `cssmin.cssmin()` function expects a string containing the CSS content to be minified, not a file path. Passing a `Path` object or a string representing a file path directly will result in a `TypeError`.
fix
Ensure you read the CSS file content into a string before passing it to the minifier. For example: `with open('style.css', 'r') as f: css_content = f.read(); minified = cssmin.cssmin(css_content)`.
affects: all versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cssmin'
The `cssmin` package is not installed in your current Python environment.
fix
Install the package using pip: `pip install cssmin`
AttributeError: module 'cssmin' has no attribute 'compress'
You are attempting to call a non-existent compression function. The primary function for minification in the `cssmin` library is `cssmin.cssmin()`.
fix
Use the correct function name: `minified_css = cssmin.cssmin(css_string)`
TypeError: expected string or bytes-like object, os.PathLike object given
You are trying to pass a file path (or a `Path` object) directly to `cssmin.cssmin()` instead of the actual CSS content from the file.
fix
Read the content of your CSS file into a string first, then pass the string to the minifier:
```python
with open('your_style.css', 'r') as f:
    css_content = f.read()
minified_css = cssmin.cssmin(css_content)
```
Upgrade
Version history
0.2.0latest on PyPI · released Oct 14, 2013
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
cssmin — pip install cssmin · libregistry