[Docpie]

Fork me on GitHub

docpie - python command line interface parser

An easy and Pythonic way to create your POSIX command line interface

Get Start Online Demo

3 steps define command line interface

How do you define your command line interface? Write a parse by yourself or spend hours learning optparse/argparse, and modify both code side and document every time you update the interface?

Life is short, man! You can do it this way:

#  cp.py
"""
My copy script

Usage:
  cp.py [options] <source_file> <target_file>
  cp.py [options] <source_file>... <target_directory> <log_file>

Options:
  -h -? --help    print this screen
  --version       print the version of this script
  -v --verbose    print more information while  running
"""

from docpie import docpie
args = docpie(__doc__)
print(args)

Now run it

$ python cp.py a.txt b.txt c.txt /tmp cp.log
{'--': False,
 '--help': False,
 '--verbose': False,
 '--version': False,
 '-?': False,
 '-h': False,
 '-v': False,
 '<log_file>': 'cp.log',
 '<source_file>': ['a.txt', 'b.txt', 'c.txt'],
 '<target_directory>': '/tmp',
 '<target_file>': None}

Write a__doc__, pass to function, DONE! Isn't it simple? try it >>


How to Install

  1. Install release version:
    pip install docpie
  2. Install nightly version:
    pip install git+git://github.com/TylerTemp/docpie.git

Keep It Simple

WYSIWYG

Only need to follow some rules, everything will work as your definition in natural language. As soon as you finish your document, the command line interface is done.

Usability

Default value, counter, exclusive group, required, optional... All these advanced functions can be defined intuitively

Customizable

It can not only deal with options like --help automaticly, but also provide many useful and handy apis that help you build complex command line interface

Don't Repeat Yourself

Keep the code side in 2 lines. All you need to do in the future update is simply update the help message.


MIT Licensed

Released under MIT free / open-sourced license , you can easily contain it no matter in personal project, group project, open sourced project or close sourced project

Get source code

Let's Get Start!


If you like this project, you can buy me a beer to help me make it better! | Flattr this