{"id":9489,"library":"argdantic","title":"argdantic: Typed CLI Interfaces with Pydantic","description":"Argdantic is a Python library that allows you to define command-line interfaces (CLIs) using Pydantic models for argument definition and type validation, combined with `argparse` for parsing. It aims to provide a modern, type-hinted approach to CLI development, leveraging Pydantic's strong data validation and `argparse`'s robust parsing capabilities. The current version is 1.3.3 and it actively maintained.","status":"active","version":"1.3.3","language":"en","source_language":"en","source_url":"https://github.com/argdantic/argdantic","tags":["CLI","Pydantic","argparse","type-hinting","command-line"],"install":[{"cmd":"pip install argdantic","lang":"bash","label":"Install argdantic"}],"dependencies":[{"reason":"Used for defining argument models and data validation.","package":"pydantic","optional":false}],"imports":[{"note":"The `parse` function was used in pre-1.0 versions. As of 1.0.0, use the `Argdantic` class and its command decorators.","wrong":"from argdantic.parse import parse","symbol":"Argdantic","correct":"from argdantic import Arqdantic"},{"note":"Field is part of Pydantic, used for adding metadata (like help text) to arguments.","symbol":"Field","correct":"from pydantic import Field"}],"quickstart":{"code":"from argdantic import Arqdantic\nfrom pydantic import Field\nimport sys\n\n# Instantiate the Arqdantic application\napp = Arqdantic()\n\n# Define a command using a decorator\n@app.command()\ndef greet(\n    name: str = Field('World', help='The name to greet.'),\n    count: int = Field(1, help='Number of times to greet.')\n):\n    \"\"\"Greets the given name multiple times.\"\"\"\n    for _ in range(count):\n        print(f\"Hello, {name}!\")\n\nif __name__ == \"__main__\":\n    # Example of how to run from the CLI:\n    # python your_script.py greet --name Alice --count 3\n    # For testing within the script, you can temporarily modify sys.argv:\n    # sys.argv = ['your_script.py', 'greet', '--name', 'Alice', '--count', '3']\n    app() # This parses sys.argv and executes the command\n","lang":"python","description":"This quickstart demonstrates how to define a simple command-line application using `argdantic`. It showcases creating an `Argdantic` instance, defining a command with type-hinted arguments and Pydantic's `Field` for help text, and running the application."},"warnings":[{"fix":"Migrate from `argdantic.parse()` with a Pydantic model to using the `Argdantic` class instance with `@app.command()` decorators and calling `app()` or `app.run()`.","message":"Major API overhaul in version 1.0.0 changed the way commands are defined and executed.","severity":"breaking","affected_versions":"<1.0.0 to >=1.0.0"},{"fix":"Ensure `if __name__ == '__main__': app()` is present in your main script file.","message":"Forgetting to call `app()` or `app.run()` at the end of your script will result in the CLI application not parsing arguments or executing commands.","severity":"gotcha","affected_versions":"All versions >=1.0.0"},{"fix":"Always use `pydantic.Field` for CLI arguments to provide explicit default values, help messages, and other metadata (e.g., `..., help='Description'`).","message":"Default values for arguments without `Field` metadata will be inferred from the type annotation, but `help` messages and custom descriptions will be missing.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Add `app()` (or `app.run()`) to the main execution block of your script, typically within `if __name__ == '__main__':`.","cause":"The `Argdantic` app instance was created, but its `app()` or `app.run()` method was not called to actually parse command-line arguments and execute the command.","error":"TypeError: 'NoneType' object is not callable"},{"fix":"Either provide a default value for the argument in the command definition (e.g., `name: str = 'Default'`) or ensure the user provides the argument via the CLI (e.g., `--name MyName`).","cause":"A non-optional argument was defined in a command function (or Pydantic model) but not provided by the user via the command line, and no default value was specified.","error":"TypeError: missing a required argument: '...' (e.g., 'name')"},{"fix":"Check the command-line syntax and ensure all provided arguments match the defined parameters. If the argument is intended, add it to the command function's signature with a type hint.","cause":"The user provided a command-line flag or argument that does not correspond to any defined parameter in the command function's signature or Pydantic model.","error":"Error: unrecognized arguments: --some-unknown-flag"}]}