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.

Installation

Install with pip

Parsable is already listed on PyPI, you can install with pip if you have the tool.

pip install --upgrade parsable

Install with setup.py

You can also run the setup.py from the source if you don’t have pip.

git clone https://github.com/fritzo/parsable.git
cd parsable
./setup.py install

Download directly

Just save parsable.py and add to your project.

Usage

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

  1. Import parsable

    import parsable
  2. Decorate functions you want parsed

    @parsable.command
    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.command
    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.dispatch()
  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
    ...

That’s it: only three little pieces of syntax!

LICENSE

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.1.2.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file parsable-0.1.2.tar.gz.

File metadata

  • Download URL: parsable-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for parsable-0.1.2.tar.gz
Algorithm Hash digest
SHA256 71fbd04526d2ea9fbc1f3cd5ae53869b846587b2ffbde78f6b840fd342ed77b2
MD5 2220f7eacfc8a1d6c96798903b1773b8
BLAKE2b-256 7f3123a0018b872c595231ba3106e72a1fd73d12c917fbb86e52cc1a31e38636

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page