Python 3 Script csscompressor Library Example to Compress or Minify CSS Files Full Project For Beginners

Python 3 Script csscompressor Library Example to Compress or Minify CSS Files Full Project For Beginners

 

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

 

 

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

See also  Python 3 Tkinter User Registration Form With Username and Password Validation Using Regular Expression Full Project For Beginners

 

python app.py

 

 

 

Leave a Reply