Skip to main content

Lightweight argument parsing using a decorator

Project description

Build status PyPI Version

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


Install from PyPI with pip

pip install parsable

Or just download and add to your project.


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.

    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)
        # ...
    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__':
  4. Use your new script

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

Advanced Usage

To show verbose information (commmand name and timing info), set the environment variable PARSABLE_VERBOSE=true.

If you use parsable for many modules in a package, you can collect them in your using parsable.find_entry_points().

from parsable import parsable
from setuptools import setup



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

Project details

Download files

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

Source Distribution

parsable-0.2.4.tar.gz (4.2 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page