Skip to content
port of werkzeug.script to argparse
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information. remove bool option


argscript is a port of werkzeug.script to argparse. Argscript generates a an argparse command line parser from the function definitions of a script.

An action is a function in the same module starting with action_ which takes a number of arguments where every argument has a default. The type of the default value specifies the type of the argument. Arguments can then be passed by using --name=value from the shell. werkzeug.script

Basic Usage is the same as werkzeug.script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Docstring for test script"""

import argscript

# actions go here
def action_foo(arg1='test'):
    """doc for action foo

    arg1 -- first argument
    print 'action_foo called with argument arg1: %s' % arg1 

def action_bar(msg='', times=1):
    """doc for action bar

    msg -- a message
    times -- number 
    print 'action_lee called with arguments msg: %s, times: %s' %(msg, times)

if __name__ == '__main__':

Now you can run the script with the -h parameter to show a basic help. The docstring from the script is reused in the help message.

$ ./ -h
usage: [-h] {foo,bar} ...

Docstring for test script

positional arguments:

optional arguments:
  -h, --help  show this help message and exit

To get the help message for a particular action call the script with the action name and the -h parameter:

$ ./ bar -h
usage: bar [-h] [--msg MSG] [--times TIMES]

doc for action bar

optional arguments:
  -h, --help     show this help message and exit
  --msg MSG      a message
  --times TIMES  number

Again the function docstring is reuesed in the help message. If you specify a description for the arguments in the doc string (variable -- doc), they are reuesed too.

Now you can run the script with the action name and the parameters, and the action function will be called with them. If you obmit a parameter, the default value will be used to call the function.

$ ./ bar --msg='Hello World' --times=4

action_lee called with arguments msg: Hello World, times: 4


You can either install the development version from github:

git clone
cd argscript
sudo python install

or install it from

pip install argscript
Something went wrong with that request. Please try again.