Skip to main content

Utility for defining then downloading and preprocessing external static files.

Project description

Build Status PyPI Status license

Copyright (C) 2013-2020 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).


grablib requires python 3.6+.

pip install grablib[build]

(You can also use simply pip install grablib to install without build requirements, this is useful when you’re not using grablib for building as it avoids installing jsmin and libsass which can be slow.)

CLI Usage

Define your static files thus: (grablib.yml)

download_root: 'static/libs'
  '': 'js/jquery.js'
    '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';"
  '': 'build_bootstrap.scss'

debug: true
build_root: 'static/prod'
  # delete the entire static/prod directory before building, this is required for sass,
  # and generally safer
  wipe: '.*'
    # concatenate jquery and codemirror into "libraries.js"
    # it won't get minified as debug is true, but without that it would
      - 'DL/js/jquery.js'
      - 'DL/codemirror/codemirror.js'
    # 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:


Library Usage

You can also call grablib from python:

from grablib import Grab

grab = Grab('path/to/definitions.json|yml')

Project details

Download files

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

Files for grablib, version 0.8
Filename, size File type Python version Upload date Hashes
Filename, size grablib-0.8-py3-none-any.whl (14.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size grablib-0.8.tar.gz (14.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page