Skip to main content

Typed Argument Parsing with Pydantic

Project description


pypi downloads versions license

Typed Argument Parsing with Pydantic


Documentation coming soon.


Install using:

  • pip3 install pydantic-argparse


import pydantic
import pydantic_argparse

class Arguments(pydantic.BaseModel):
    """Arguments for CLI"""
    # Required Args
    aaa: str = pydantic.Field(description="I'm a required string")
    bbb: int = pydantic.Field(description="I'm a required integer")
    ccc: bool = pydantic.Field(description="I'm a required bool")

    # Optional Args
    ddd: bool = pydantic.Field(False, description="I'm an optional bool (default False)")
    eee: bool = pydantic.Field(True, description="I'm an optional bool (default True)")

def main() -> None:
    """Main example function."""
    # Create Parser and Parse Args
    parser = pydantic_argparse.ArgumentParser(
        description="Example Description",
        epilog="Example Epilog",
    args = parser.parse_typed_args()

    # Print Args

if __name__ == "__main__":
$ python3 --help

usage: Example [-h] [-v] --aaa AAA --bbb BBB --ccc | --no-ccc [--ddd] [--no-eee]

Example Description

required arguments:
  --aaa AAA          I'm a required string
  --bbb BBB          I'm a required integer
  --ccc, --no-ccc    I'm a required bool

optional arguments:
  --ddd              I'm an optional bool (default False)
  --no-eee           I'm an optional bool (default True)

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

Example Epilog
$ python3 --aaa hello --bbb 123 --no-ccc

aaa='hello' bbb=123 ccc=False ddd=False eee=True

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic-argparse-0.3.1.tar.gz (11.5 kB view hashes)

Uploaded source

Built Distribution

pydantic_argparse-0.3.1-py3-none-any.whl (14.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page