Skip to main content

python shell scripts made easy

Project description


Oliver Tonnhofer <>


The primary goal of scriptine is to make it easy to write shell scripts with python.

Scriptine does two things to solve this goal:

  • Make it easy to create scripts and commands.

  • Make it easy to work with files, directories and other shell commands.

To create commands with scriptine, you just create a normal python function for each command of your script and scriptine handles the rest. It creates command line option parser and calls the right function with the right options.

The second part of scriptine is a bunch of convenience classes and functions that make it easy to work with files, directories and other shell commands. It abstracts the different python modules like os, os.path, shutil and subprocess and offers a simple and easy to use interface. scriptine comes with an enhanced version of Jason Orendorff’s path module.


  • Easy command creation. Each command is just a function.

    • Automatic option parsing

    • Automatic help text (--help)

  • Log handling (with -v, --verbose and -q, --quite handling)

  • Testing scripts in dry-mode. All destructive functions/methods are wrapped and will not be called when the -n or --dry-run option is set.

  • Easy execution of other shell scripts.

  • Convenient working with files and directories.


Here is a small example script:

import scriptine

def example_command(name, countdown=False, repeat=10):
    """Show how scriptine works."""
    if countdown:
        for i in range(repeat, 0, -1):
            print i,
    print 'Hello, %s!' % name

if __name__ == '__main__':

Usage of our small script:

% python
Usage: command [options]

  -h, --help  show this help message and exit

  example  Show how scriptine works.
% python example Pete
Hello, Pete!
% python example Pete --countdown --repeat 5
5 4 3 2 1 Hello, Pete!

A more complex example:

from scriptine import run, path, log
from import call

def to_png_command(dirname, outdir='out', extension='jpeg'):
    Convert all files with extension in dirname to .png.
    Only convert if result does not exists or is older.

    :param dirname: where to search for images
    :param outdir: where to store the results
    :param extension: file extension to convert
    outdir = path(outdir)
    if not outdir.exists(): outdir.makedirs()
    for f in path(dirname).files('*.'+extension):
        outfile = outdir / f.namebase + '.png'
        if not outfile.exists() or f.newer(outfile):
  'converting %s to %s', f, outfile)
            call(['convert', f, outfile])

if __name__ == '__main__':

The help text:

% python to-png  --help
Usage: to-png [options] dirname

 Convert all files with extension in dirname to .png. Only
convert if result does not exists or is older.

Required arguments:
dirname: where to search for images

  -h, --help        show this help message and exit
  --outdir=out      where to store the results
  --extension=jpeg  file extension to convert
  -n, --dry-run     don't actually do anything
  -v, --verbose     be more verbose
  -q, --quite       be more silent

And the result:

% python to-png ~/images/ --extension gif
/Users/olt/images/foo.gif out/foo.png
/Users/olt/images/bar.gif out/bar.png


The documentation can be found at


scriptine is still in development. Some parts will be changed and some more functionality will be added. Follow the development at Comments and bug fixes are welcomed.


0.2.0a1 (2009-11-09)
  • renamed path.getcwd to path.cwd

  • converted properties to methods for values that might change (e.g. size, mtimes, etc)

  • add path.newer method

0.1.0 (2009-11-05)
  • first release

Project details

Download files

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

Source Distribution

scriptine-0.2.0a1.tar.gz (38.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page