Skip to main content

Pydantic Argparse

Typed Argument Parsing with Pydantic

Help

See documentation for help.

Installation

Installation with pip is simple:

$ pip install pydantic-argparse

Example

import pydantic
import pydantic_argparse


class Arguments(pydantic.BaseModel):
    # Required Args
    string: str = pydantic.Field(description="a required string")
    integer: int = pydantic.Field(description="a required integer")
    flag: bool = pydantic.Field(description="a required flag")

    # Optional Args
    second_flag: bool = pydantic.Field(False, description="an optional flag")
    third_flag: bool = pydantic.Field(True, description="an optional flag")


def main() -> None:
    # Create Parser and Parse Args
    parser = pydantic_argparse.ArgumentParser(
        model=Arguments,
        prog="Example Program",
        description="Example Description",
        version="0.0.1",
        epilog="Example Epilog",
    )
    args = parser.parse_typed_args()

    # Print Args
    print(args)


if __name__ == "__main__":
    main()
$ python3 example.py --help
usage: Example Program [-h] [-v] --string STRING --integer INTEGER --flag |
                       --no-flag [--second-flag] [--no-third-flag]

Example Description

required arguments:
  --string STRING    a required string
  --integer INTEGER  a required integer
  --flag, --no-flag  a required flag

optional arguments:
  --second-flag      an optional flag (default: False)
  --no-third-flag    an optional flag (default: True)

help:
  -h, --help         show this help message and exit
  -v, --version      show program's version number and exit

Example Epilog
$ python3 example.py --string hello --integer 42 --flag
string='hello' integer=42 flag=True second_flag=False third_flag=True

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for pydantic-argparse 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-argparse 0.6.0
File Size Uploaded
pydantic-argparse-0.6.0.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-argparse 0.6.0
File Interpreter ABI Platform
pydantic_argparse-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.1 kB

Release files / pydantic-argparse-0.6.0.tar.gz

Download URL pydantic-argparse-0.6.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
037be8cb8858a9897bbec033294553f74f8bf002bd171434c482e9ba00ff9c26
BLAKE2b-256 checksum
How to use checksums
4dd6cabac586cd3ec69a6558f5a3bb85436d7f594db588d69d684e6dd5f31e7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.10.2 Linux/5.15.0-52-generic

Release files / pydantic_argparse-0.6.0-py3-none-any.whl

Download URL pydantic_argparse-0.6.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
142a4ce4bf11269de910487a4242e16ef903c8ccb1e6e9c659252b8b1f463f8a
BLAKE2b-256 checksum
How to use checksums
1f566e669410187dacbd20b0b9dec1e2bf44cc3d02d5a888147a4b2503041e20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.10.2 Linux/5.15.0-52-generic

Release history Release notifications | RSS feed

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page