Skip to main content

JavaScript (ES5) minifier

Project description


A JavaScript minifier command-line utility written fully in Python; uses calmjs.parse as the underlying library.


crimp serves as the front-end to calmjs.parse.

Both these libraries had their origin in slimit, a package that provided a Python based solution for handling JavaScript code, which is often used for situations where the usage of commonly used minifiers, which are typically written in Node.js, is impractical from a pure Python environment. However, slimit had not been maintained for a number of years. As of 2017, with many issues that impacted the correctness of the generated code remain outstanding, calmjs.parse was forked from slimit, and crimp was created as a front end for the former.


The following command may be executed to source the latest stable version of crimp wheel from PyPI for installation into the current Python environment.

$ pip install crimp


As crimp is a package that offers a command of the same name, executing the command after installation with the --help flag will reveal the options that are available.

$ crimp --help
usage: crimp [input_file [input_file ...]] [-h] [-O <output_path>] [-m] [-p]
             [-s [<sourcemap_path>]] [--version] [-o] [--drop-semi]
             [--indent-width n] [--encoding <codec>]

positional arguments:
  input_file            path(s) to input file(s)

optional arguments:
  -h, --help            show this help message and exit
  -O <output_path>, --output-path <output_path>
                        output file path
  -m, --mangle          enable all basic mangling options
  -p, --pretty-print    use pretty printer (omit for minify printer)
  -s [<sourcemap_path>], --source-map [<sourcemap_path>]
                        enable source map; filename defaults to
                        <output_path>.map, if identical to <output_path> it
                        will be written inline as a data url
  --version             show version information
  --indent-width n      indentation width for pretty printer
  --encoding <codec>    the encoding for file-based I/O; stdio relies on
                        system locale

basic mangling options:
  -o, --obfuscate       obfuscate (mangle) names
  --drop-semi           drop unneeded semicolons (minify printer only)

Typically, the program will be invoked with a single or multiple input files (if they are to be combined into a single file), and optionally with the -m flag to denote that it is safe to have all the mangle options enabled.

Please note that all input files must be listed before the flags, as this forced grouping of all input files result in a less ambiguous listing of files, given that there are flags for specifying target output files, which will be overwritten without prompt.

Standard pretty/minified printing

To minify some file:

$ crimp project.js -O project.min.js

To minify some file with just variable name obfuscation:

$ crimp project.js -m -O project.min.js

Pretty printing the minified file back onto stdout:

$ crimp project.min.js -p

Reading input from stdin and writing out to a file. Note that if a SIGINT (typically Ctrl-C or Ctrl-Break), the output file will not be opened for writing.

$ crimp -O demo.js

Source map generation

For source map generation, enable the -s flag.

$ crimp project.js -O project.min.js -s

The above will write out the source map file as, and the reference to that (the sourceMappingURL) will also be appended to the output file as a comment. To specify a specific location, pass the name as a parameter.

$ crimp project.js -O project.min.js -s

Inline source maps (where the sourceMappingURL is the data URL of the base64 encoding of the JSON serialization of the source map) are supported; these can be produced by supplying the argument with the same name used for the output file, like so:

$ crimp project.js -O project.min.js -s project.min.js


Parsing a moderately sized file takes 10x as much time as uglifyjs

This is due to the implementation done by calmjs.parse as a set of generator functions that produce very minimum output, and that the standard Python implementation has a very high overhead performance cost for function calls. The advantage with that approach is that maximum flexibility can be achieved (due to the ease of which unparsing workflows can be set up), while the drawback is obvious.


1.0.0 - 2017-09-26

Initial release.

Project details

Release history Release notifications

This version
History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
crimp-1.0.0-py2.py3-none-any.whl (14.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Sep 26, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page