Skip to content

jthacker/terseparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

terseparse: Terse argument parsing

Terseparse was designed for user friendly typing of arguments and constructing parsers with minimal boiler plate.

Install

$ pip install terseparse

Features

  • A composable syntax for constructing parsers
  • Extensive set of types with helpful error messages
  • All arguments and parsers require documentation strings
  • Metavars are created automatically
  • Metavars provide type information
  • Subparser names and descriptions are displayed in help messages
  • Arguments in subparsers are added to all children parsers
  • Debugging of the parser can be done at runtime
  • Unique namespace for arguments, no conflicts with other properties

Usage

This example is taken from the argparse documentation

p = Parser('cmd', 'Process some integers',
    Arg('integers', 'an integer for the accumulator',
        metavar='N', type=int, nargs='+'),
    Arg('--sum', 'sum the integers (default: find the max)',
        dest='accumulate', action='store_const',
        const=sum, default=max))
_, args = p.parse_args('1 2 3 4'.split())
print(args.ns.integers)

Argument Namespace

Unlike argparse, arguments are stored in a unique namespace under args.ns. This is done to avoid conflicts between existing methods in args and parameter values being parsed (e.g. .keys() would conflict with a keys parameter).

Debugging

Terseparse argument parsing can be debugged by passing in --terseparse-debug as the first argument. It must be the first argument so that the parsing of the rest of the arguments can take place as they are parsed.

Development

Release

  • Bump the version in terseparse/version.py.
  • Merge to master.
  • Push the corresponding tag.
  • Github actions pushes to pypi.

About

Argument validation and easy construction of parsers with minimal boiler plate.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages