{"id":6478,"library":"typed-argument-parser","title":"Typed Argument Parser (Tap)","description":"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.","status":"active","version":"1.12.0","language":"en","source_language":"en","source_url":"https://github.com/swansonk14/typed-argument-parser","tags":["argument parser","cli","type hints","argparse","pydantic","developer tools"],"install":[{"cmd":"pip install typed-argument-parser","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for parsing docstrings to generate help messages.","package":"docstring-parser","optional":false},{"reason":"Used for runtime inspection of type hints.","package":"typing-inspect","optional":false},{"reason":"Optional, for using `tapify` with Pydantic models (introduced in v1.10.0).","package":"pydantic","optional":true}],"imports":[{"symbol":"Tap","correct":"from tap import Tap"},{"symbol":"tapify","correct":"from tap import tapify"},{"note":"Used to mark class attributes that should not be parsed as command-line arguments (introduced in v1.12.0).","symbol":"TapIgnore","correct":"from tap import TapIgnore"},{"note":"Used to mark class attributes that should be parsed as positional command-line arguments (introduced in v1.12.0).","symbol":"Positional","correct":"from tap import Positional"}],"quickstart":{"code":"from tap import Tap\n\nclass SimpleArgumentParser(Tap):\n    name: str # Your name\n    language: str = 'Python' # Programming language\n    package: str = 'Tap' # Package name\n    stars: int # Number of stars\n    max_stars: int = 5 # Maximum stars\n\nif __name__ == '__main__':\n    args = SimpleArgumentParser().parse_args()\n    print(f'My name is {args.name} and I give the {args.language} package '\n          f'{args.package} {args.stars}/{args.max_stars} stars!')","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade Python to 3.10+ or downgrade `typed-argument-parser` to `<1.12.0`.","message":"Version 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.","severity":"breaking","affected_versions":">=1.12.0"},{"fix":"Ensure build systems are compatible with `pyproject.toml` and direct filesystem paths to `tap` are updated if used.","message":"Version 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.","severity":"breaking","affected_versions":">=1.10.1"},{"fix":"Pass `known_only=True` to `tapify` if your command-line interface should gracefully ignore unrecognized arguments.","message":"When 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`.","severity":"gotcha","affected_versions":">=1.8.0"},{"fix":"If reproducibility info needs to come from a specific git repo, explicitly set the `repo_path` parameter in the `save` method.","message":"The 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.","severity":"gotcha","affected_versions":">=1.7.1"},{"fix":"Be aware of the implicit boolean flag behavior. For explicit boolean parsing, call `parse_args(explicit_bool=True)`.","message":"Boolean 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()`.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}