Registry / serialization / argdantic

argdantic

JSON →
library1.3.3pypypi✓ verified 83d ago

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.

pip install argdantic
INSTALL
IMPORT
SIG · ARGDANTIC
A
argdantic
serializationpythonv1.3.3
Install
3.4s avg
Import
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.3 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 28.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.4s · import 0.000s · 28MB
27MB installed
● package 27MB
Code
Verified usage

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

ArgParser
from argdantic import ArgParser
from argdantic import Arqdantic
ArgField
from argdantic import ArgField
convert
from argdantic import convert

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.

from argdantic import Arqdantic from pydantic import Field import sys # Instantiate the Arqdantic application app = Arqdantic() # Define a command using a decorator @app.command() def greet( name: str = Field('World', help='The name to greet.'), count: int = Field(1, help='Number of times to greet.') ): """Greets the given name multiple times.""" for _ in range(count): print(f"Hello, {name}!") if __name__ == "__main__": # Example of how to run from the CLI: # python your_script.py greet --name Alice --count 3 # For testing within the script, you can temporarily modify sys.argv: # sys.argv = ['your_script.py', 'greet', '--name', 'Alice', '--count', '3'] app() # This parses sys.argv and executes the command
argdantic --version
Debug
Known issues
breakingMajor API overhaul in version 1.0.0 changed the way commands are defined and executed.
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()`.
affects: <1.0.0 to >=1.0.0
gotchaForgetting to call `app()` or `app.run()` at the end of your script will result in the CLI application not parsing arguments or executing commands.
fix
Ensure `if __name__ == '__main__': app()` is present in your main script file.
affects: All versions >=1.0.0
gotchaDefault values for arguments without `Field` metadata will be inferred from the type annotation, but `help` messages and custom descriptions will be missing.
fix
Always use `pydantic.Field` for CLI arguments to provide explicit default values, help messages, and other metadata (e.g., `..., help='Description'`).
affects: All versions
Upgrade
Version history
1.3.3latest on PyPI · released Jan 10, 2025
Audit
Dependencies
pydanticrequiredUsed for defining argument models and data validation.
Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
argdantic — pip install argdantic · libregistry