Typed Argument Parser (Tap) is a Python library that modernizes `argparse` by leveraging type hints for command-line argument parsing. It offers benefits like static type checking, code completion, and improved source code navigation. Additionally, it provides `tapify`, a function inspired by Google's Python Fire, to effortlessly run functions or initialize classes directly from command-line arguments while automatically handling type conversions. Currently at version 1.12.0, Tap is actively developed with a regular release cadence, supporting Python 3.10 and newer.
pip install typed-argument-parserVerified import paths — ran on the pinned version, not inferred.
This example demonstrates defining a `Tap` class with typed arguments, including required and optional arguments with default values. The arguments are then parsed from the command line and used in the program.
Upgrade Python to 3.10+ or downgrade `typed-argument-parser` to `<1.12.0`.
Ensure build systems are compatible with `pyproject.toml` and direct filesystem paths to `tap` are updated if used.
Pass `known_only=True` to `tapify` if your command-line interface should gracefully ignore unrecognized arguments.
If reproducibility info needs to come from a specific git repo, explicitly set the `repo_path` parameter in the `save` method.
Be aware of the implicit boolean flag behavior. For explicit boolean parsing, call `parse_args(explicit_bool=True)`.
Change the import statement from `import typed_argument_parser` or `from typed_argument_parser import Tap` to `from tap import Tap` or `from tap import tapify`.
Ensure all required arguments for the class's `__init__` method are either provided via command-line arguments (e.g., `--arg_name value`) or have default values defined in the class or `Tap` subclass.
Provide command-line arguments with values that are compatible with their specified type hints (e.g., use `--age 25` for an `int` argument, not `--age twenty-five`).