Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Command line argument parsing library for python

Project description

Argument parsing for python developers


import argument
f = argument.Arguments()
#Requried arguments, first argument will be stored as "candy"
f.require("candy", help="Candy name")

#optional unnamed value

#optional value, set a default, can be changed by adding: --num=30, or -n=30
    help="How many pieces?",
#add a switch, a flag with no argument
    help="Reverse ordering",
f.switch("unwrap", help="unwrapcandy", abbr="u")

#Process data before saving it
f.process("candy", lambda x: x.upper())

#Parse num as integer
f.process("num", lambda x: int(x))

f.validate("num", lambda x: x > 10)

#get data
arguments, errors = f.parse()


python tests/ bubblegum

{‘num’: 25, ‘soda’: None, ‘reverse’: False, ‘candy’: ‘BUBBLEGUM’, ‘unwrap’: False}

python bubblegum cubacola

{‘num’: 25, ‘soda’: ‘cubacola’, ‘reverse’: False, ‘candy’: ‘BUBBLEGUM’, ‘unwrap’: False}

python tests/ bubblegum -r -n=123 –unwrap

{‘num’: 123, ‘soda’: None, ‘reverse’: True, ‘candy’: ‘BUBBLEGUM’, ‘unwrap’: True}

python tests/ bubblegum –n=5

{‘num’: 5, ‘soda’: None, ‘reverse’: False, ‘candy’: ‘BUBBLEGUM’, ‘unwrap’: False}

Autogenerated help:

print(f) ``` Usage: [OPTIONS] CANDY

Required arguments: CANDY Candy name

Optional arguments: SODA N/A

Options: -n –num=25 How many pieces?

Switches: -r –reverse Reverse ordering -u –unwrap unwrapcandy ```

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 argument, version 1.4.0
Filename, size File type Python version Upload date Hashes
Filename, size argument-1.4.0.tar.gz (4.6 kB) File type Source Python version None 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