Skip to main content

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, positional
from pathlib import Path

@arcparser
class Args:
    path: Path = positional()
    recurse: bool = flag("-r")
    item_limit: int = 100
    output_path: Path | None

args = Args.parse()
print(f"Scanning {args.path}...")
...
Help output of this parser
usage: program.py [-h] [-r] [--item-limit ITEM_LIMIT] [--output-path OUTPUT_PATH] path

positional arguments:
path

options:
-h, --help            show this help message and exit
-r, --recurse
--item-limit ITEM_LIMIT
--output-path OUTPUT_PATH

For more examples see Examples.

Installation

# Using pip
$ pip install arcparse

Features

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 NameErrors. 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.14 forward thanks to PEP 649.

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

arcparse-1.3.2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

arcparse-1.3.2-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file arcparse-1.3.2.tar.gz.

File metadata

  • Download URL: arcparse-1.3.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.12 Darwin/25.3.0

File hashes

Hashes for arcparse-1.3.2.tar.gz
Algorithm Hash digest
SHA256 e4a692d822b05459ffb5056f1509e0cc7028d40e3a11a95b10df46bc17e098bf
MD5 1f5a5b59cfb7a239bbcb1afd2c156c89
BLAKE2b-256 4217340a3ceea10be16a1683850ad365d19a9482613732b1cb6a103ede25dc63

See more details on using hashes here.

File details

Details for the file arcparse-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: arcparse-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.12 Darwin/25.3.0

File hashes

Hashes for arcparse-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 206247fd1d19e19c9829a306343e2ae38c409a3e38313ecaaa9d27be6881dd99
MD5 7f71c3b6fd986d8aaff9ae11c4463863
BLAKE2b-256 05f2411dba4ecde12599c9040ff97c59b2b93e040b798e1b978bde1e2b884b86

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