Skip to main content

p2a

pydantic models to argparse CLIs

Build Status codecov License PyPI

Overview

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

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.

Fields with types that cannot be mapped to arguments are skipped. parse_extra_args_model warns about a skipped field only when an argument for it is passed.

Metadata

Release files for p2a 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for p2a 0.1.3
File Size Uploaded Provenance Actions
p2a-0.1.3.tar.gz 14.4 kB Without provenance Details for p2a-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for p2a 0.1.3
File Interpreter ABI Platform Actions
p2a-0.1.3-py3-none-any.whl Python 3 none any Details for p2a-0.1.3-py3-none-any.whl

Total release size: 28.7 kB

Release files / p2a-0.1.3.tar.gz

Download URL p2a-0.1.3.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
808006701fc083168c74d86c42e0e7d80b02a487f05b4507ba07a69a2a61be04
BLAKE2b-256 checksum
How to use checksums
a6129d68bccdc9c0cb4270ae5826fb10377e8439b9743c23cd2b15c72be79264
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / p2a-0.1.3-py3-none-any.whl

Download URL p2a-0.1.3-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8174a57344f16443033d374600864e0de48153162be3245ebae21d8a6e81c40
BLAKE2b-256 checksum
How to use checksums
ffad4d9e5b18a11e0a568650b1ddb896f3991e24f969cf7a5223db3577f645d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for p2a 0.1.3

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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