The Artima Developer Community
Sponsored Link

The Explorer
plac, the easiest command line arguments parser in the Python world
by Michele Simionato
June 2, 2010
Announcing the first public release of plac, a declarative command line arguments parser designed for simplicity and concision.


I would like to announce to the world the first public release of plac:

Plac is a wrapper over argparse and works in all versions of Python starting from Python 2.3 up to Python 3.1.

With blatant immodesty, plac claims to be the easiest to use command line arguments parser module in the Python world. Its goal is to reduce the learning curve of argparse from hours to minutes. It does so by removing the need to build a command line arguments parser by hand: actually it is smart enough to infer the parser from function annotations.

Here is a simple example (in Python 3) to whet your appetite:

$ cat
def main(arg: "required argument"):
    "do something with arg"
    print('Got %s' % arg)

if __name__ == '__main__':
    import plac; # passes sys.argv[1:] to main

$ python -h
usage: [-h] arg

do something with arg

positional arguments:
  arg         required argument

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

$ python
usage: [-h] arg error: too few arguments

$  python arg
Got arg

$  python arg1 arg2
usage: [-h] arg error: unrecognized arguments: arg2

You can find in the documentation a lot of other simple and not so simple examples:


Michele Simionato

P.S. answering an unspoken question: yes, we really needed yet another command line arguments parser! ;)

Talk Back!

Have an opinion? Readers have already posted 12 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Michele Simionato adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Michele Simionato started his career as a Theoretical Physicist, working in Italy, France and the U.S. He turned to programming in 2003; since then he has been working professionally as a Python developer and now he lives in Milan, Italy. Michele is well known in the Python community for his posts in the newsgroup(s), his articles and his Open Source libraries and recipes. His interests include object oriented programming, functional programming, and in general programming metodologies that enable us to manage the complexity of modern software developement.

This weblog entry is Copyright © 2010 Michele Simionato. All rights reserved.

Sponsored Links


Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use