Credits: Thanks to Cristian Tomatis for contributing this example.
import requests url = 'https://www.toptal.com/developers/cssminifier/raw' data = {'input': open('style.css', 'rb').read()} response = requests.post(url, data=data) print response.text
Credits: Thanks to Noam Yorav-Raphael for contributing this example.
>>> import requests >>> requests.post('https://www.toptal.com/developers/cssminifier/raw', data=dict(input='p { color : red; }')).text 'p{color:red}'
Credits: Thanks to Kyle S. for contributing this to the site.
# -*- coding: utf-8 -*- import sys import requests try: css_file = sys.argv[1] except: print("Missing input file") sys.exit() # Grab the file contents with open(css_file, 'r') as c: css = c.read() # Pack it, ship it payload = {'input': css} url = 'https://www.toptal.com/developers/cssminifier/raw' print("Requesting mini-me of {}. . .".format(c.name)) r = requests.post(url, payload) # Write out minified version minified = css_file.rstrip('.css')+'.min.css' with open(minified, 'w') as m: m.write(r.text) print("Minification complete. See {}".format(m.name))
Click on the language of your choice to see an example: