Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

doc to argparse driven by docopt

Project Description

doc to argparse driven by docopt

Define your command line interface (CLI) from a docstring (rather than the other way around). Because it’s easy. It’s quick. Painless. Then focus on what’s actually important - using the arguments in the rest of your program.

The problem is that this is not always flexible. Still need all the features of argparse? Now have the best of both worlds… all the extension such as argcomplete or Gooey but with the simple syntax of docopt.


Latest pypi stable release

pip install argopt

Latest development release on github

Pull and install in the current directory:

pip install -e git+


The list of all changes is available either on Github’s Releases or on crawlers such as


Standard docopt docstring syntax applies. Additionally, some improvements and enhancements are supported, such as type checking and default positional arguments.

from argopt import argopt

def main(doc):
    parser = argopt(doc, version='0.1.2-3.4')
    # parser.print_help()

    args = parser.parse_args()
    print (args)

if __name__ == '__main__':
    doc = '''
Example programme description.
You should be able to do
    args = argopt(__doc__).parse_args()
instead of
    args = docopt(__doc__)

Usage: [-h | options] <x> [<y>...]

    <x>                   A file.
    --anarg=<a>           Description here [default: 1e3:int].
    -p PAT, --patts PAT   Or [default: None:file].
    --bar=<b>             Another [default: something] should
                          auto-wrap something in quotes and assume str.
    -f, --force           Force.


def argopt(doc='', argparser=argparse.ArgumentParser, **_kwargs):
  Note that `docopt` supports neither type specifiers nor default
  positional arguments. We support both here.

  doc  : docopt compatible, with optional type specifiers
       [default: '':str]
  argparser  : Argument parser class [default: argparse.ArgumentParser]
  version  : Version string [default: None:str]
  _kwargs  : any `argparser` initialiser arguments

  out  : argparser object (default: argparse.ArgumentParser)

  Extension syntax example: [default: 1e3:int].

  You should be able to do
      parser = argopt(__doc__)
      args   = parser.parse_args()
  instead of
      args = docopt(__doc__)

  (better) subparser support
  (docopt extension) action choices
  (docopt extension) action count


To run the testing suite please make sure tox ( is installed, then type tox from the command line.

Where tox is unavailable, a Makefile-like setup is provided with the following command:

$ python make alltests

To see all options, run:

$ python make


OSI approved.

Copyright (c) 2016 Casper da Costa-Luis.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at


Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
argopt-0.3.1-py2.py3-none-any.whl (15.0 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Apr 20, 2016
argopt-0.3.1.tar.gz (17.6 kB) Copy SHA256 Checksum SHA256 Source Apr 20, 2016 (24.5 kB) Copy SHA256 Checksum SHA256 Source Apr 20, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting