arglite
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;Trueif present, otherwiseFalse.
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/--flagand--flag=value/-f=valuesyntaxes are supported. - Values containing spaces work when passed via the shell's normal quoting rules.
- Empty string values (
--name "") are preserved. ast.literal_evalis used for type inference when no explicittypeis given.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e7e8346c7d92b578e7b29c88cd4d230f14f681f54f9d5c9f10e295a9631246a
|
|
| MD5 |
a191c80c9308520eb7aed760668c4f79
|
|
| BLAKE2b-256 |
5ff5cba1be1f83ec9d9259f15702a9ad05942ac46b82187c4ad7504242c981f1
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51fdc8dc3b7dc565390973d2f865619d8a2fdcc77da892f3349a5ac03bee44d9
|
|
| MD5 |
b355ed9ac72158df5799d02998dce0fa
|
|
| BLAKE2b-256 |
07dc47a988d77baa6dce875439c0fde151eca341840ff769f75c80d670eb052c
|