Skip to main content

Typed Argument Parsing with Pydantic

Project description

pydantic-argparse

pypi downloads versions license

Typed Argument Parsing with Pydantic

Help

Documentation coming soon.

Installation

Install using:

  • pip3 install pydantic-argparse

Example

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(
        model=Arguments,
        prog="Example",
        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 [-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)

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

Example Epilog
$ python3 example.py --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.2.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

pydantic_argparse-0.2.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic-argparse-0.2.0.tar.gz.

File metadata

  • Download URL: pydantic-argparse-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.7 Darwin/20.6.0

File hashes

Hashes for pydantic-argparse-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5be2130c0b86fc5f9bded3dfa14aa926f69a18e54d978c24f69a7dcd53b3529b
MD5 c8cc54e94cbeac24f059e243bf15ef8a
BLAKE2b-256 549adacabca1b30950cd38468c30a36b24da392002c69e98b5192bcba961f4f5

See more details on using hashes here.

File details

Details for the file pydantic_argparse-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_argparse-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.7 Darwin/20.6.0

File hashes

Hashes for pydantic_argparse-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46003dcf48b9193a54308307efa556f9d9b9d243f63ee48309c4150533f33846
MD5 341fa5c176065e2b586c338053a54038
BLAKE2b-256 1a6639d4b5f862b3504f320da3d13995f3d0e2c115ed2ce00ec6b9fb616a8b72

See more details on using hashes here.

Supported by

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