This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Lightweight argument parsing using a decorator

Project Description

Parsable is a lightweight decorator-based command line parser library. Parsable was written to be simpler than argparse, optparse, and argh.

Installation

Install from PyPI with pip

pip install parsable

Or just download parsable.py and add to your project.

Usage

Parsable uses just two pieces of syntax: a @parsable command decorator, and a parsable() dispatch function.

  1. Import parsable.

    from parsable import parsable
    
  2. Decorate functions you want parsed. Parsable inspects the function to decide how to parse arguments. Arguments without default values are parsed as strings. Default arguments of any type T can be parsed as long as T(some_string) can do the parsing.

    @parsable
    def my_function(required_arg, optional_bool=True, optional_int=1):
        '''Help messages are not just a good idea, they are required'''
        # parsable automatically converts types based on default arguments:
        assert isinstance(required_arg, str)
        assert isinstance(optional_string, bool)
        assert isinstance(optional_int, int)
        # ...
    
    @parsable
    def do_stuff_with_files(*filenames, inplace=True):
        '''This does something to each file'''
        # ...
    
  3. Dispatch at the end of the script.

    if __name__ == '__main__':
        parsable()
    
  4. Use your new script

    $ python my_script.py my_function demo optional_int=5
    ...
    
    # parsable replaces - with _ to make functions easier to read
    $ python my_script.py do-stuff-with-files *.py in-place=false
    ...
    

LICENSE

Parsable is dual-licensed under the MIT and GPL2 licenses.

Release History

Release History

This version
History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.4

History Node

0.1.2

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
parsable-0.2.2.tar.gz (4.0 kB) Copy SHA256 Checksum SHA256 Source Nov 8, 2015

Supported By

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