Skip to main content

arglite

PyPI version

A lightweight, explicit argument parsing library for Python programs.

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

Declare the flags your program expects, then access them as attributes on the global parser:

import arglite

arglite.parser.require("name", type=str)
arglite.parser.optional("count", default=1, type=int)
arglite.parser.flag("verbose")

def main():
    print(arglite.parser.name)
    print(arglite.parser.count)
    print(arglite.parser.verbose)

if __name__ == "__main__":
    main()

Run it with:

python main.py --name Yo --count 5 --verbose

Declarations

  • parser.require(name, short=None, type=None) — required flag; exits with an error if missing.
  • parser.optional(name, short=None, default=None, type=None) — optional flag with an optional default value.
  • parser.flag(name, short=None) — boolean flag; True if present, otherwise False.

If short is not given, the first letter of the flag name is used automatically (e.g. --name can also be -n).

Accessing values

Declared flags are accessed directly on the parser:

arglite.parser.name
arglite.parser.count
arglite.parser.verbose

HELP!

Help appears when -h / --help is used.

Errors

When arguments are missing, unknown, or cannot be converted to the declared type, you'll see clear errors:

ERROR: --name is required but was not provided
ERROR: Unknown flag --foo; the program does not call for it
ERROR: Value for --count could not be converted to int: 'abc'

Notes

  • Flags are case-sensitive.
  • Both -f / --flag and --flag=value / -f=value syntaxes are supported.
  • Values containing spaces work when passed via the shell's normal quoting rules.
  • Empty string values (--name "") are preserved.
  • ast.literal_eval is used for type inference when no explicit type is given.

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.20.0.tar.gz (9.8 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.20.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for arglite-0.20.0.tar.gz
Algorithm Hash digest
SHA256 3e7e8346c7d92b578e7b29c88cd4d230f14f681f54f9d5c9f10e295a9631246a
MD5 a191c80c9308520eb7aed760668c4f79
BLAKE2b-256 5ff5cba1be1f83ec9d9259f15702a9ad05942ac46b82187c4ad7504242c981f1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for arglite-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51fdc8dc3b7dc565390973d2f865619d8a2fdcc77da892f3349a5ac03bee44d9
MD5 b355ed9ac72158df5799d02998dce0fa
BLAKE2b-256 07dc47a988d77baa6dce875439c0fde151eca341840ff769f75c80d670eb052c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.30.5

2 files

0.30.0

2 files

This release

0.20.0 This release

2 files

0.10.1

2 files

0.10.0

2 files

0.9.9

2 files

0.9.8

2 files

0.9.7

2 files

0.9.6

1 file

0.9.5

1 file

0.9.4

1 file

0.9.3

1 file

0.9.2

1 file

0.9.1

1 file

0.9.0

1 file

0.8.6

1 file

0.8.5

1 file

0.8.0

1 file

0.7.5

1 file

0.7.0

1 file

0.6.0

1 file

0.5.0

1 file

0.4.1

1 file

0.4.0

1 file

0.3.5

1 file

0.3

1 file

0.2

1 file

0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page