Skip to main content

Command line arguments. Made simple.

Project description

cli-args

Do you belong to those who have to look up the calls you have to make to argparse? And are you longing for a way to just import the parsed arguments as you would import sys.argv? Then cli-args is the way to go!

cli-args is a Python library for an easier parsing of command line arguments. It wraps the popular argparse to allow importing parsed arguments from anywhere in the code. One of the key features is the way you define what arguments you accept. By providing a dictionary - that also can be read from a JSON file! - you can easily set all available command line arguments at one specific, easy-to-find place.

Get it!

pip install cli-args

Use it!

demo.py

import cli_args


# or: cli_args.from_file('path/to/schema.json')
cli_args.from_schema({
    "description": "Process some integers.",
    "arguments": [
        {
            "short": "a",
            "long": "integer_a",
            "var": "NUMBER",
            "help": "The first integer",
            "default": 0,
            "type": "int"
        },
        {
            "short": "b",
            "long": "integer_b",
            "var": "NUMBER",
            "help": "The second integer",
            "default": "0",
            "type": "int"
        }
    ]
})


print(cli_args.argv['integer_a']) # 3
print(cli_args.argv['integer_b']) # 5

python demo.py --integer_a=3 --integer_b=5

License

Licensed under the MIT License. Happy forking :)

Project details


Download files

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

Files for cli-args, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size cli_args-1.1.0-py3-none-any.whl (3.3 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

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