Skip to main content

A lightweight, dynamic arg parser for fun, but not profit.

Project description

arglite

PyPI version

A lightweight, dynamic argument parsing library for Python programs with klugy support for typing variables.

I made this for a teaching machine project I'm working on (I needed a custom argument parser for reasons), and I'm always too impatient to use argparse.

Installation

Find this tool on PyPI: pip install arglite

Usage

Check this out:

import arglite

def main():
  # Can include explicit requirement
  print(arglite.parser.required.a)
  # Can be an implicit requirement
  print(arglite.parser.b)
  # Can also be purely optional
  print(arglite.parser.optional.c)
  print(arglite.parser.optional.d)

if __name__ == "__main__":
  main()

Run using python main.py -a Yo --b that is -c.

For the more intrepid among us, this also works:

from arglite import parser as cliarg

def main():
  # Can include explicit requirement
  print(cliarg.required.a)
  # Can be an implicit requirement
  print(cliarg.b)
  # Can also be purely optional
  print(cliarg.optional.c)
  print(cliarg.optional.d)

if __name__ == "__main__":
  main()

HELP!

Help now appears when no variables are provided or when requested by use of -h (--h) or -help (--help).

Errors

When errors are present (i.e. flags are provided which aren't used in the code or flags used aren't provided), you'll see errors:

✗ ERROR: A value was provided for A, but the program doesn't call for it
✗ ERROR: A value was expected for a, but not was provided as a flag
✗ ERROR: A value was expected for b, but not was provided as a flag

Notes

  • Flags with no value are automatically converted to True boolean
  • The module uses ast.literal_eval, so "{'a':'b'}" will convert to a dict (all quotes required)

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

arglite-0.10.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

arglite-0.10.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file arglite-0.10.1.tar.gz.

File metadata

  • Download URL: arglite-0.10.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for arglite-0.10.1.tar.gz
Algorithm Hash digest
SHA256 3f97319eb7e7c5c2d3212bf0269666081f3faeb68f6a50832433e9a494dc7e34
MD5 68013c0e7e193a4a0b5b7b34c84d0a94
BLAKE2b-256 29c12076b0051158ed0b7cc1ddf865afb7ebfe4b611081b4e8cc1daf83094023

See more details on using hashes here.

File details

Details for the file arglite-0.10.1-py3-none-any.whl.

File metadata

  • Download URL: arglite-0.10.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for arglite-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dfb7449bac5f73a400a83a1531b00ccb3c83a14fd1ee6242516f27e9063072c8
MD5 6d0722143b6e04b0acccef63237ef6c9
BLAKE2b-256 caa7ea2e32fa779850a377a4f1b97392236b33b6945d39b93aacc85e62cd2eec

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