Skip to content

Instantly share code, notes, and snippets.

@brandonhimpfen
Created April 24, 2026 03:29
Show Gist options
  • Select an option

  • Save brandonhimpfen/b1a9e00f91257c26a0568b4a8bd02059 to your computer and use it in GitHub Desktop.

Select an option

Save brandonhimpfen/b1a9e00f91257c26a0568b4a8bd02059 to your computer and use it in GitHub Desktop.
Minimize your CSS file with a command line interface (CLI) using Python.
import argparse
import csscompressor
parser = argparse.ArgumentParser(description='Minimize CSS code.')
parser.add_argument('input_file', help='the input CSS file')
parser.add_argument('output_file', help='the output file for the minimized CSS')
args = parser.parse_args()
# Load the CSS file
with open(args.input_file, 'r') as f:
css_text = f.read()
# Minimize the CSS
minimized_css = csscompressor.compress(css_text)
# Write the minimized CSS to a file
with open(args.output_file, 'w') as f:
f.write(minimized_css)
print('Successfully minimized CSS code!')

To run this script, you'll need to have the csscompressor library installed. You can install it by running pip install csscompressor.

Run the script using the following command:

python minimize_css.py src.css dist.css

Where src.css is the input file and dist.css is the output file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment