Typed Argument Parsing with Pydantic
Project description
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.
Project details
Release history Release notifications | RSS feed
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.6.1.tar.gz
(13.6 kB
view hashes)
Built Distribution
Close
Hashes for pydantic_argparse-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c93905319ee32fd533d04913fc8eac99bd6ffbc5e15a3145b9bbda6ba1cc386 |
|
MD5 | 41b27db34c18564f70bd3485dc9c8666 |
|
BLAKE2b-256 | 23c45d66200050bb625b0285be02f5fac7b8dd81020af4bd2adb04ab08b8c74b |