This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Blargparse extends argparse.ArgumentParser, adding an add_aggregate method that can help you separate your user interface logic from everything else.

How to use

Install from PyPI.

pip install blargparse

Here’s the simplest way to use it.

b = BlargParser()
b.add_argument('--left', '-l', type = int, default = 0)
b.add_argument('--right', 'r', type = int, default = 100)
b.add_aggregate('numbers', lambda args: range(args.left, args.right))

b.parse_args([]).numbers == range(0, 100)

You can get a bit fancier.

b = BlargParser()
b.add_argument('--left', '-l', type = int, default = 0)
b.add_argument('--right', 'r', type = int, default = 100)
def f(args):
    output = range(args.left, args.right)
    del(args.left, args.right)
b.add_aggregate(f)

b.parse_args([]).numbers == range(0, 100)

Why

I wrote Blargparse because I found myself doing stuff like this.

# Construct the parser.
a = argparse.ArgumentParser()
a.add_argument('--left', '-l', type = int, default = 0)
a.add_argument('--right', 'r', type = int, default = 100)

# Parse the arguments
import sys
ns = a.parse_args(sys.argv)

# Convert them into the form I want for my application.
numbers = range(ns.left, ns.right)

The input argument that made most sense to me while programming the thing was the numbers range, but I thought it was easiest if the end user could specify this range as a combination of --left and --right flags. And I might want to change that based on what users seem to prefer.

The above approach is fine because it’s small, but I had several arguments like this spread across several subparsers in different places, and the construction, parsing, and conversion of the arguments thus wound up spread across functions and even files.

With vanilla argparse I wound up doing stuff like this.

def _build_subparsers(argparser):
    'This adds subparsers to the parser.'
    subparsers = argparser.add_subparsers()
    # ...

def _apply_aggregates(args):
    args.range = range(args.left, args.right)
    del(args.left, args.right)

argparser = argparser.ArgumentParser()
_build_subparsers(argparser)
args = argparser.parse_args()
_apply_aggregates(args)

This is a bit better except that it groups subparsers together and aggregates together. I wanted subparsers to be grouped with relevant aggregates, and I did not want to group by whether something was a subparser or an aggregate; I think of the aggregates as components of the subparsers.

A more confusing alternative would have been to come up with my own non-argparse interface on top of this for specifying groupings of subparsers and aggregates.

Release History

Release History

0.0.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
blargparse-0.0.3.tar.gz (2.1 kB) Copy SHA256 Checksum SHA256 Source Aug 8, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development 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