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.7.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.7.0
File Size Uploaded Provenance
pydantic_argparse-0.7.0.tar.gz 15.7 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 38.2 kB

Release files / pydantic_argparse-0.7.0.tar.gz

Download URL pydantic_argparse-0.7.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2715b2bb6867c5af9026d375519f5ff406854d70523747f1e14531ffda37aa59
BLAKE2b-256 checksum
How to use checksums
4f19a0b7a76383f185db2aba9be415daacdb15f3af6022bb64604e74c5c560ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.2 Linux/5.15.0-60-generic

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

Download URL pydantic_argparse-0.7.0-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
229c793a8ec237c5e45f6d20b765a2ce95c322173de50d31c4a6ccfab67f0815
BLAKE2b-256 checksum
How to use checksums
90bc9843de2a7721de04bb0eed44c644ef1f47f6cf6c9a8461661af5afdd5481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.2 Linux/5.15.0-60-generic

Security for pydantic-argparse 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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