Metadata-Version: 2.5
Name: p2a
Version: 0.1.2
Summary: pydantic models to argparse CLIs
Project-URL: Repository, https://github.com/python-project-templates/p2a
Project-URL: Homepage, https://github.com/python-project-templates/p2a
Author-email: the p2a authors <t.paine154@gmail.com>
License: Apache-2.0
License-File: LICENSE
Keywords: argparse,cli,command-line,models,pydantic,validation
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.11
Requires-Dist: pkn<0.6,>=0.3
Provides-Extra: develop
Requires-Dist: build; extra == 'develop'
Requires-Dist: bump-my-version; extra == 'develop'
Requires-Dist: check-dist; extra == 'develop'
Requires-Dist: codespell; extra == 'develop'
Requires-Dist: hatchling; extra == 'develop'
Requires-Dist: mdformat; extra == 'develop'
Requires-Dist: mdformat-frontmatter; extra == 'develop'
Requires-Dist: mdformat-tables>=1; extra == 'develop'
Requires-Dist: pytest; extra == 'develop'
Requires-Dist: pytest-cov; extra == 'develop'
Requires-Dist: ruff; extra == 'develop'
Requires-Dist: twine; extra == 'develop'
Requires-Dist: ty; extra == 'develop'
Requires-Dist: uv; extra == 'develop'
Requires-Dist: wheel; extra == 'develop'
Description-Content-Type: text/markdown

# p2a

pydantic models to argparse CLIs

[![Build Status](https://github.com/python-project-templates/p2a/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/p2a/actions/workflows/build.yaml)
[![codecov](https://codecov.io/gh/python-project-templates/p2a/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/p2a)
[![License](https://img.shields.io/github/license/python-project-templates/p2a)](https://github.com/python-project-templates/p2a)
[![PyPI](https://img.shields.io/pypi/v/p2a.svg)](https://pypi.python.org/pypi/p2a)

## Overview

A function is provided to automatically expose fields as command line arguments.

```python
import sys
from pydantic import BaseModel
from p2a import parse_extra_args_model


class MyPluginConfig(BaseModel, validate_assignment=True):
    extra_arg: bool = False
    extra_arg_with_value: str = "default"
    extra_arg_literal: Literal["a", "b", "c"] = "a"


model = MyPluginConfig()
parse_extra_args_model(model, sys.argv)

# > my-cli --extra-arg --extra-arg-with-value "test" --extra-arg-literal b
```

For integration with existing `argparse` CLIs, a helper function to create an `argparse.SubParser` is also provided: `p2a.create_model_parser`.

> [!NOTE]
> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
