<div align="center">
<a href="https://github.com/anastasds/pydantic2-argparse">
<img src="https://raw.githubusercontent.com/anastasds/pydantic2-argparse/master/docs/assets/images/logo.svg" width="50%">
</a>
<h1>
Pydantic Argparse
</h1>
<p>
<em>Typed Argument Parsing with Pydantic</em>
</p>
<a href="https://pypi.python.org/pypi/pydantic2-argparse">
<img src="https://img.shields.io/pypi/v/pydantic2-argparse.svg">
</a>
<a href="https://github.com/anastasds/pydantic2-argparse">
<img src="https://img.shields.io/pypi/pyversions/pydantic2-argparse.svg">
</a>
<a href="https://github.com/anastasds/pydantic2-argparse/blob/master/LICENSE.md">
<img src="https://img.shields.io/github/license/anastasds/pydantic2-argparse.svg">
</a>
<br>
<a href="https://github.com/anastasds/pydantic2-argparse/actions/workflows/tests.yml">
<img src="https://img.shields.io/github/actions/workflow/status/anastasds/pydantic2-argparse/tests.yml?label=tests">
</a>
<a href="https://github.com/anastsds/pydantic2-argparse/actions/workflows/tests.yml">
<img src="https://img.shields.io/coveralls/github/anastasds/pydantic2-argparse">
</a>
<a href="https://github.com/anastasds/pydantic2-argparse/actions/workflows/linting.yml">
<img src="https://img.shields.io/github/actions/workflow/status/anastasds/pydantic2-argparse/linting.yml?label=linting">
</a>
<a href="https://github.com/anastasds/pydantic2-argparse/actions/workflows/typing.yml">
<img src="https://img.shields.io/github/actions/workflow/status/anastasds/pydantic2-argparse/typing.yml?label=typing">
</a>
</div>
## Help
See [documentation](https://github.com/anastasds/pydantic2-argparse) for help.
## Installation
Installation with `pip` is simple:
```console
$ pip install pydantic2-argparse
```
## Example
```py
import pydantic
import pydantic2_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 = pydantic2_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()
```
```console
$ 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
```
```console
$ 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.
Raw data
{
"_id": null,
"home_page": "https://github.com/anastasds/pydantic2-argparse",
"name": "pydantic2-argparse",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "python,pydantic,argparse,typed,validation",
"author": "Hayden Richards",
"author_email": "SupImDos@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ad/67/b546cb734a8dacb0a5dd280a43f5d66a6c25f160ee3b30eff3e9c4b92c6c/pydantic2_argparse-0.9.2.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n <a href=\"https://github.com/anastasds/pydantic2-argparse\">\n <img src=\"https://raw.githubusercontent.com/anastasds/pydantic2-argparse/master/docs/assets/images/logo.svg\" width=\"50%\">\n </a>\n <h1>\n Pydantic Argparse\n </h1>\n <p>\n <em>Typed Argument Parsing with Pydantic</em>\n </p>\n <a href=\"https://pypi.python.org/pypi/pydantic2-argparse\">\n <img src=\"https://img.shields.io/pypi/v/pydantic2-argparse.svg\">\n </a>\n <a href=\"https://github.com/anastasds/pydantic2-argparse\">\n <img src=\"https://img.shields.io/pypi/pyversions/pydantic2-argparse.svg\">\n </a>\n <a href=\"https://github.com/anastasds/pydantic2-argparse/blob/master/LICENSE.md\">\n <img src=\"https://img.shields.io/github/license/anastasds/pydantic2-argparse.svg\">\n </a>\n <br>\n <a href=\"https://github.com/anastasds/pydantic2-argparse/actions/workflows/tests.yml\">\n <img src=\"https://img.shields.io/github/actions/workflow/status/anastasds/pydantic2-argparse/tests.yml?label=tests\">\n </a>\n <a href=\"https://github.com/anastsds/pydantic2-argparse/actions/workflows/tests.yml\">\n <img src=\"https://img.shields.io/coveralls/github/anastasds/pydantic2-argparse\">\n </a>\n <a href=\"https://github.com/anastasds/pydantic2-argparse/actions/workflows/linting.yml\">\n <img src=\"https://img.shields.io/github/actions/workflow/status/anastasds/pydantic2-argparse/linting.yml?label=linting\">\n </a>\n <a href=\"https://github.com/anastasds/pydantic2-argparse/actions/workflows/typing.yml\">\n <img src=\"https://img.shields.io/github/actions/workflow/status/anastasds/pydantic2-argparse/typing.yml?label=typing\">\n </a>\n</div>\n\n## Help\nSee [documentation](https://github.com/anastasds/pydantic2-argparse) for help.\n\n## Installation\nInstallation with `pip` is simple:\n```console\n$ pip install pydantic2-argparse\n```\n\n## Example\n```py\nimport pydantic\nimport pydantic2_argparse\n\n\nclass Arguments(pydantic.BaseModel):\n # Required Args\n string: str = pydantic.Field(description=\"a required string\")\n integer: int = pydantic.Field(description=\"a required integer\")\n flag: bool = pydantic.Field(description=\"a required flag\")\n\n # Optional Args\n second_flag: bool = pydantic.Field(False, description=\"an optional flag\")\n third_flag: bool = pydantic.Field(True, description=\"an optional flag\")\n\n\ndef main() -> None:\n # Create Parser and Parse Args\n parser = pydantic2_argparse.ArgumentParser(\n model=Arguments,\n prog=\"Example Program\",\n description=\"Example Description\",\n version=\"0.0.1\",\n epilog=\"Example Epilog\",\n )\n args = parser.parse_typed_args()\n\n # Print Args\n print(args)\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n```console\n$ python3 example.py --help\nusage: Example Program [-h] [-v] --string STRING --integer INTEGER --flag |\n --no-flag [--second-flag] [--no-third-flag]\n\nExample Description\n\nrequired arguments:\n --string STRING a required string\n --integer INTEGER a required integer\n --flag, --no-flag a required flag\n\noptional arguments:\n --second-flag an optional flag (default: False)\n --no-third-flag an optional flag (default: True)\n\nhelp:\n -h, --help show this help message and exit\n -v, --version show program's version number and exit\n\nExample Epilog\n```\n\n```console\n$ python3 example.py --string hello --integer 42 --flag\nstring='hello' integer=42 flag=True second_flag=False third_flag=True\n```\n\n## License\nThis project is licensed under the terms of the MIT license.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Typed Argument Parsing with Pydantic",
"version": "0.9.2",
"project_urls": {
"Homepage": "https://github.com/anastasds/pydantic2-argparse",
"Repository": "https://github.com/anastasds/pydantic2-argparse"
},
"split_keywords": [
"python",
"pydantic",
"argparse",
"typed",
"validation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "08f28161869c6a990c6e19ff0306823ad028277a852eb51e27cf3495eff07880",
"md5": "f96044bfa08673d7f986196cdaaa8130",
"sha256": "e375ce3fbbf7fe4c45c93bfbf2c230570a7cb4136f4f72cca6e43a5e44af628f"
},
"downloads": -1,
"filename": "pydantic2_argparse-0.9.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f96044bfa08673d7f986196cdaaa8130",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 25199,
"upload_time": "2024-01-18T18:45:35",
"upload_time_iso_8601": "2024-01-18T18:45:35.801731Z",
"url": "https://files.pythonhosted.org/packages/08/f2/8161869c6a990c6e19ff0306823ad028277a852eb51e27cf3495eff07880/pydantic2_argparse-0.9.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ad67b546cb734a8dacb0a5dd280a43f5d66a6c25f160ee3b30eff3e9c4b92c6c",
"md5": "4369e036837d0e20f59d1ca278c99ad8",
"sha256": "76c8ad548986e39fed85afda94d54364c3175d3595065530430e6e94af33275d"
},
"downloads": -1,
"filename": "pydantic2_argparse-0.9.2.tar.gz",
"has_sig": false,
"md5_digest": "4369e036837d0e20f59d1ca278c99ad8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 16596,
"upload_time": "2024-01-18T18:45:37",
"upload_time_iso_8601": "2024-01-18T18:45:37.087754Z",
"url": "https://files.pythonhosted.org/packages/ad/67/b546cb734a8dacb0a5dd280a43f5d66a6c25f160ee3b30eff3e9c4b92c6c/pydantic2_argparse-0.9.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-18 18:45:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "anastasds",
"github_project": "pydantic2-argparse",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pydantic2-argparse"
}