Registry / serialization / typed-argument-parser

typed-argument-parser

JSON →
library1.12.0pypypi✓ verified 86d ago

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-parser
INSTALL
IMPORT
SIG · TYPED-ARGUMENT-PAR
T
typed-argument-parser
serializationpythonv1.12.0
Install
1.6s avg
Import
99ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.12.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.105s · 18.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.094s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Tap
from tap import Tap
tapify
from tap import tapify
TapIgnore
from tap import TapIgnore
Used to mark class attributes that should not be parsed as command-line arguments (introduced in v1.12.0).
Positional
from tap import Positional
Used to mark class attributes that should be parsed as positional command-line arguments (introduced in v1.12.0).

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.

from tap import Tap class SimpleArgumentParser(Tap): name: str # Your name language: str = 'Python' # Programming language package: str = 'Tap' # Package name stars: int # Number of stars max_stars: int = 5 # Maximum stars if __name__ == '__main__': args = SimpleArgumentParser().parse_args() print(f'My name is {args.name} and I give the {args.language} package ' f'{args.package} {args.stars}/{args.max_stars} stars!')
Debug
Known issues
breakingVersion 1.12.0 (and newer) drops support for Python 3.9. Users on Python 3.9 must upgrade their Python version to 3.10 or newer, or pin `typed-argument-parser` to an older version.
fix
Upgrade Python to 3.10+ or downgrade `typed-argument-parser` to `<1.12.0`.
affects: >=1.12.0
breakingVersion 1.10.1 refactored the project structure, moving code from `tap/` to `src/tap` and `setup.py` to `pyproject.toml`. While direct imports are generally unaffected (`from tap import ...`), this might impact users with custom build systems or those relying on internal package structure.
fix
Ensure build systems are compatible with `pyproject.toml` and direct filesystem paths to `tap` are updated if used.
affects: >=1.10.1
gotchaWhen using `tapify` to run functions or initialize classes, by default it will raise an error if additional, unneeded arguments are provided on the command line. To ignore extra arguments, use `known_only=True`.
fix
Pass `known_only=True` to `tapify` if your command-line interface should gracefully ignore unrecognized arguments.
affects: >=1.8.0
gotchaThe behavior for handling reproducibility information's `repo_path` changed in v1.7.1. By default, it now uses the git repository of the directory containing the executed file, rather than the current working directory.
fix
If reproducibility info needs to come from a specific git repo, explicitly set the `repo_path` parameter in the `save` method.
affects: >=1.7.1
gotchaBoolean arguments (e.g., `arg: bool = False`) are set to `True` by merely including the `--arg` flag. If `arg: bool = True`, `--arg` sets it to `False`. For explicit `True`/`False` values on the command line (e.g., `--arg True`), `explicit_bool=True` must be passed to `parse_args()`.
fix
Be aware of the implicit boolean flag behavior. For explicit boolean parsing, call `parse_args(explicit_bool=True)`.
affects: *
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'typed_argument_parser'
The user is attempting to import the library using its PyPI package name (`typed_argument_parser`) instead of its actual Python module name (`tap`).
fix
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`.
TypeError: __init__ missing 1 required positional argument: 'arg_name'
A class used with `tapify` or as a `Tap` subclass has a constructor (`__init__`) with required arguments that are not provided through the command line and also lack default values.
fix
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.
ValueError: invalid literal for int() with base 10: 'abc'
A command-line argument was provided with a value that cannot be successfully converted into the type specified by the corresponding type hint in the `Tap` class.
fix
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`).
Upgrade
Version history
1.12.0latest on PyPI · released Mar 28, 2026
Audit
Dependencies
docstring-parserrequiredRequired for parsing docstrings to generate help messages.
typing-inspectrequiredUsed for runtime inspection of type hints.
pydanticoptionalOptional, for using `tapify` with Pydantic models (introduced in v1.10.0).
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
typed-argument-parser — pip install typed-argument-parser · libregistry