playmolecule.plac module#

class playmolecule.plac.Annotation(help=None, kind='positional', abbrev=None, type=None, choices=None, metavar=None, required=False, nargs=None)#

Bases: object

classmethod from_(obj)#

Helper to convert an object into an annotation, if needed

class playmolecule.plac.ArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)#

Bases: ArgumentParser

An ArgumentParser with .func and .argspec attributes, and possibly .commands and .subparsers.

addsubcommands(commands, obj, title=None, cmdprefix='')#

Extract a list of subcommands from obj and add them to the parser


Can be overridden to preprocess command-line arguments

case_sensitive = True#

Call the underlying function with the args. Works also for command containers, by dispatching to the right subparser.


May raise a SystemExit


Extract the arguments from the attributes of the passed function and return a populated ArgumentParser instance.


Useful for debugging


Returns a decorator annotating a function with the given annotations. This is a trick to support function annotations in Python 2.X., arglist=None, eager=True, version=None)#

If obj is a function or a bound method, parse the given arglist by using the parser inferred from the annotations of obj and call obj with the parsed arguments. If obj is an object with attribute .commands, dispatch to the associated subparser.

playmolecule.plac.flg(arg, help=None, abbrev=None)#

Decorator for annotating flags


Given a callable return an object with attributes .args, .varargs, .varkw, .defaults. It tries to do the “right thing” with functions, methods, classes and generic callables.


An object is an annotation object if it has the attributes help, kind, abbrev, type, choices, metavar.


Any object with an __iter__ method which is not a string or class

playmolecule.plac.opt(arg, help=None, type=None, abbrev=None, choices=None, metavar=None, required=False, nargs=None)#

Decorator for annotating optional arguments

playmolecule.plac.parser_from(obj, **confparams)#

obj can be a callable or an object with a .commands attribute. Returns an ArgumentParser.


Extracts the configuration of the underlying ArgumentParser from obj


Returns year-month-day


Returns year-month-day hour-minute-second