Welcome folks today in this blog post we will be compressing
or minifying
css files using csscompressor
library in python 3. All the full source code of the application is given below.
Get Started
In order to get started we need to install the following library using the pip
command as shown below
pip install csscompressor
After installing this library you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 |
import codecs import csscompressor def css_minify(src,dst): with codecs.open(src, 'r', 'utf-8') as src_file: minified = csscompressor.compress(src_file.read()) with codecs.open(dst, 'w', 'utf-8') as dst_file: dst_file.write(minified) css_minify("input.css","outputminified.css") |
Here in this python script you need to replace the input file
and output file
paths accordingly. Now run the python script by typing the below command
python app.py