Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install assetgen

How to install assetgen

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install assetgen
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
0.3.4Never BuiltWhy not?
0.2 Available View build log
0.1 Available View build log
Linux (32-bit)
0.3.4Never BuiltWhy not?
0.3.0 Available View build log
0.2.2 Available View build log
0.2 Available View build log
0.1 Available View build log
Linux (64-bit)
0.3.4 Available View build log
0.3.0 Available View build log
0.2.2 Available View build log
0.2 Available View build log
0.1 Available View build log
Public Domain
Lastest release
version 0.3.4 on May 22nd, 2013

Assetgen is intended as a replacement for the various ad-hoc scripts that often get written to build/manage JavaScript/CSS files.


The default support includes:

  • Compiling CoffeeScript/TypeScript source files into JavaScript.
  • Minifying with UglifyJS/UglifyJS2 -- including constant folding support.
  • Generating source maps for CoffeeScript, TypeScript and minified JavaScript sources.
  • Compiling and minifying CSS from Less, Roole, SASS, SCSS and Stylus source files.
  • Generating variants of the same stylesheet for internationalisation (flipping left to right).
  • Embedding image/font resources as data: URIs within CSS stylesheets to minimise latency.
  • Concatenating multiple source files into one file to minimise the number of HTTP requests.
  • Creating distinct files with the hash of the content embedded in the filename so as to work effectively with web caches.
  • Dynamically fetching source files and embedded resources from HTTP/HTTPS URLs.
  • Creating a JSON manifest file for use in your web app's static handlers.
  • Generating files processed by a templating language (e.g. for inserting content from other files).

The tool is driven by the configuration you specify in an assetgen.yaml file, e.g.

# Example assetgen.yaml configuration


- js/base.js:
      - %(AMPIFY_ROOT)s/third_party/jslibs/json.js

- js/app.js:
      - https://raw.github.com/tav/jsutil/master/define.coffee
      - static/js/models.coffee
      - static/js/views.coffee
      - DEBUG=false
        - DEBUG=true

- js/encoder.js:
      - encoder/detect.ts
      - encoder/format.ts
      - encoder/encode.ts
    sourcemaps: true

- js/content-inserter.js
       - static/html/content.html # plain html content
       - static/js/Content.coffee # content handling logic
       - raw: "})();"
     template: |
       (function(){var htmlContent = ${source|trim,jsliteral};
     # the source parameter gets processesed for each static source
     # file (i.e. not raw strings) which is not processed in any way
     # i.e. not CoffeeScript/TypeScript files.
     # Also, templates only works when source maps are disabled
     sourcemaps: false

- gfx/*:
    source: static/gfx/*
    type: binary

- css/site.css:
      - raw: |
          // Public Domain (-) 2013 The Ampify Authors.
          // See the Ampify UNLICENSE file for details.
      - static/css/site.sass
      - static/css/*.sass
      - static/gfx/*
    bidi: true
    embed.path.root: static
    embed.url.base: /.static/


- static/js/consts.js:
    source: static/js/consts.coffee
    compress: false

- static/js/consts-dev.js:
    source: static/js/consts-dev.coffee
    compress: false

  NODE_PATH.prefix: static/js

output.directory: appengine/static
output.hashed: true
output.manifest: appengine/assets.json

  css.compress: false
  js.compress: false

To take advantage of the embedding within stylesheets just replace url() entries with embed() entries in your source stylesheet files -- whether that is less, sass, scss, stylus or plain old CSS.

You can control which config options gets used by specifying the --profile parameter. This will override default values with the values specified for the given profile. So, in the above example, specifying --profile dev will use all the profile.dev options.

And, whilst you are developing, you can use the --watch command-line parameter to tell assetgen to monitor file changes and rebuild all appropriate files. Watch also monitors changes to the assetgen.yaml file, so you can update the config without having to restart assetgen.

During development, one often runs --watch with a dev profile, e.g.

assetgen --profile dev --watch

Then, to create the release/production builds, just remove the built files and regenerate, i.e.

assetgen --clean && assetgen

The above commands assume that you've commited an assetgen.yaml file into a git repository. Assetgen will then use git to auto-detect the file from within the current repository. If you are not using git or haven't committed the config file, you can of course specify it explicitly, e.g.

assetgen assetgen.yaml --profile dev --watch
assetgen assetgen.yaml --clean && assetgen assetgen.yaml

If you are using bash, you can take advantage of the tab-completion for command line parameters support within assetgen by adding the following to your ~/.bashrc or equivalent:

_assetgen_completion() {
    COMPREPLY=( $( \

complete -o default -F _assetgen_completion assetgen

And, finally, you can specify custom handlers for assetgen to call when generating a file of a given type. For example, to override the builtin js handler with one which just lower-cases all the source content, create your extension, e.g. kickass-extension.py:

class KickassAsset(Asset):

    def generate(self):
        content = ''.join(read(source).lower() for source in self.sources)
        self.emit(self.path, content)

register_handler('js', KickassAsset)

Then run assetgen with the --extension path/to/kickass-extension.py parameter specified.


Usage: assetgen [<path/to/assetgen.yaml> ...] [options]

    If you don't specify assetgen.yaml file paths, then `git
    ls-files *assetgen.yaml` will be used to detect all config
    files in the current repository. So you need to be inside
    a git repository's working tree.

    And if you specify a URL as a `source`, then it will be
    downloaded to ~/.assetgen -- you can override this by
    setting the env variable $ASSETGEN_DOWNLOADS

  -h, --help        show this help message and exit
  -v, --version     show program's version number and exit
  --clean           remove all generated files
  --debug           set debug mode
  --extension=PATH  specify a python extension file (may be repeated)
  --force           force rebuild of all files
  --nuke            remove all generated and downloaded files
  --profile=NAME    specify a profile to use
  --watch           keep running assetgen on a loop


To contribute any patches simply fork the repository using GitHub and send a pull request to https://github.com/tav, thanks!


All of the code has been released into the Public Domain. Do with it as you please.

-- Enjoy, tav <tav@espians.com>

Subscribe to package updates

Last updated May 22nd, 2013

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.