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.0.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.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: arglite-0.10.0.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.0.tar.gz
Algorithm Hash digest
SHA256 9a86e8465e86fe93db7da602ffb42b72d34a97634efe4abebc12e8597e478698
MD5 046e7d20f7eb14cfc5b3e9c3b5913bff
BLAKE2b-256 03481769661e5cdf7632c56489e9938f8a1e034b4b13f6be1323e76a65ecd6eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arglite-0.10.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 022d53bcd3303e451dd1f6eaeca47cce5ef4931498b106a9dd55981541d09384
MD5 c9b477f4e103b26b11fa2a2f172704f6
BLAKE2b-256 8aaf9254e091fb4de460dfa8686ba496a0274a2c65d0491b26599b60490b29be

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