Declare program arguments in a type-safe way
Project description
arcparse
Declare program arguments in a type-safe way.
This project builds on top of argparse
by adding type-safety and allowing a more expressive argument parser definition.
Example usage
from arcparse import arcparser, flag
@arcparser
class Args:
path: Path
recurse: bool = flag("-r")
item_limit: int = 100
output_path: Path | None
args = Args.parse()
print(f"Scanning {args.path}...")
...
For more examples see Examples.
Installation
# Using pip
$ pip install arcparse
Features
- Positional, Option and Flag arguments
- Multiple values per argument
- Name overriding
- Type conversions
- Mutually exclusive groups
- Subparsers
- Parser inheritance
Credits
This project was inspired by swansonk14/typed-argument-parser.
Known issues
Annotations
from __future__ import annotations
makes all annotations strings at runtime. This library relies on class variable annotations's types being actual types. inspect.get_annotations(obj, eval_str=True)
is used to evaluate string annotations to types in order to assign converters. If an argument is annotated with a non-builtin type which is defined outside of the argument-defining class body the type can't be found which results in NameError
s. This is avoidable either by only using custom types which have been defined in the argument-defining class body (which is restrictive), or alternatively by not using the annotations
import which should not be necessary from python 3.13 forward thanks to PEP 649.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file arcparse-1.0.0.tar.gz
.
File metadata
- Download URL: arcparse-1.0.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/5.15.150.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f1233678d4205e22fa5cb565d3e1b2312a3baa0b9c3d116c4ffde75755ff582 |
|
MD5 | 8aea23ec0464a72c1c7d1c1ca79df324 |
|
BLAKE2b-256 | d6f158e9beccbc201c5e932537433c458c4bb980616f617bbc9dbfac9569ffb9 |
File details
Details for the file arcparse-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: arcparse-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/5.15.150.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff679e145bd18c18e07a76a5658c516d397de008ef2a822c16a1dabee9f30a7f |
|
MD5 | 694a2f72c8d8d990954a8982d796652a |
|
BLAKE2b-256 | 8d324e1c4dacf51be027a0d69a7a57832def304caa7700d26de30deeadd872d2 |