skip to navigation
skip to content

grablib 0.3

Utility for defining then downloading and preprocessing external static files.

Copyright (C) 2013-2016 Samuel Colvin

Kind of like bower, but in Python, and simpler, and with some more features.

grablib can:

  • download files from urls, including extracting selectively from zip files.
  • create .grablib.lock which retains hashes of all downloaded files meaning assets can’t change unexpectedly.
  • compile sass/scss/css using libsass.
  • concatenate and minify javascript using jsmin.

Definition files can either be JSON or YAML (see examples).

CLI Usage

Define your static files thus: (grablib.yml)

download_root: "static/libs"
download:
  "http://code.jquery.com/jquery-1.11.3.js": "js/jquery.js"
  "https://github.com/twbs/bootstrap-sass/archive/v3.3.6.zip":
    "bootstrap-sass-3.3.6/assets/(.+)$": "bootstrap-sass/"

  "GITHUB/codemirror/CodeMirror/5.8.0/lib/codemirror.js": "codemirror/"
  # simple scss file to import and compile bootstrap from above,
  # generally this would be in your code
  # this file just reads `@import 'bootstrap-sass/stylesheets/bootstrap';`
  "https://git.io/v1Z5J": "build_bootstrap.scss"

debug: true
build_root: "static/prod"
build:
  cat:
    # concatenate jquery and codemirror into "libraries.js"
    # it won't get minified as debug is true, but without that it would
    "libraries.js":
      - "DL/js/jquery.js"
      - "DL/codemirror/codemirror.js"
  sass:
    # compile all css, scss and sass files which don't start with _ from the "download_root"
    # into the "css" directory, here that will just be build_bootstrap.scss which will
    # build the whole of bootstrap.
    # debug: true means you'll get map files and a copy of sass files so maps work properly.
    "css": "DL/"

Then download and build you static files with just:

grablib

Library Usage

You can also call grablib from python:

from grablib import Grab

grab = Grab('path/to/definitions.json|yml')
grab.download()
grab.build()
 
File Type Py Version Uploaded on Size
grablib-0.3-py35-none-any.whl (md5) Python Wheel py35 2016-12-01 12KB
grablib-0.3.tar.gz (md5) Source 2016-12-01 8KB