Skip to main content

A simple argument parser

Project description

qargs (quick args)

qargs is an argument parser.

qargs is fast and easy to use. It is great for rapid prototyping and CLI utilities that need to minimize startup time.

qargs uses POSIX style argument syntax (mostly). It was implemented according to the syntax described by the The Open Group Base Specifications (Chapter 12: Utility conventions). The standard can be read here. It intentionally deviates from the standard by not implementing 12.1, 2a and 2b and 12.2, guideline 9.

Why write another argument parser?

Simply put, I don't like how other parsers work. I believe that they are needlessly difficult to use and most require too much boilerplate code. Because of this, I frequently found myself writing one-off parsers to meet my needs. I decided that instead of constantly reinventing the wheel, I needed more permanent solution; hence qargs.

Installation

qargs can be installed with pip: pip install qargs

Example Usage

qargs provides a single function, parse_args.

Called without any arguments, parse_args will do a few handy things for you:

  • gather all arguments in the .operands attribute
  • gather all files in the .files attribute
  • gather all directories in the .directories attribute
  • determine whether to read stdin with the .stdin attribute
import qargs

args = qargs.parse_args()

for f in args.files:
    # do a thing to each file

parse_args can be called with a specification to tell it what flags to look for.

import qargs

spec = [
    ['c', 'color'],
    ['v', 'verbose'],
]

args = qargs.parse_args(spec)

if args.color:
    # be colorful

if args.verbose:
    # be verbose

You can provide another value in the spec to capture arguments. If the value evaluates to a bool, the argument is blindly captured. If the value is callable, that callable is used to validate the argument.

import os
import qargs


def validate_config_file(f):
    return os.path.isfile(f) and f.endswith('.conf')


spec = [
    ['c', 'config-file', validate_config_file],
]

args = qargs.parse_args(spec)

with open(args.config_file, 'r') as cf
    # read config file

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

quick-arguments-0.0.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quick_arguments-0.0.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file quick-arguments-0.0.1.tar.gz.

File metadata

  • Download URL: quick-arguments-0.0.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for quick-arguments-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6691a1e8dfb05d8f039a7e544063ddd4d7911fba93336fd13f8b08b2066cc9c5
MD5 ad933f0e3ed0e3235abefe9dc563add8
BLAKE2b-256 885411a6bd5e10a1455594093a23b1aa2c6a0d16ab1847980e7e634218d75ed7

See more details on using hashes here.

File details

Details for the file quick_arguments-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: quick_arguments-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for quick_arguments-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7a15b0eea4dbd0314bc0a35a68d143b510140f9b3eb2179b5882253ac9b9d76
MD5 d033b728f56e7bc1791d89425231c06b
BLAKE2b-256 8b06c6b90d55f032c7f0de3f0380116d3e51530d8e4a1d2d31965aed216e1c6b

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