FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

python-project-templates/p2a: pydantic models to argparse CLIs · GitHub

Repository navigation

Public

About

pydantic models to argparse CLIs

Topics

Resources

Code of conduct

Stars

1 star

Watchers

2 watching

Forks

Repository files navigation

p2a

pydantic models to argparse CLIs

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.

Note

This library was generated using copier from the Base Python Project Template repository.

About

pydantic models to argparse CLIs

Topics

Resources

Code of conduct

Stars

1 star

Watchers

2 watching

Forks

Releases

Contributors

Languages


Back | FazBrowse Home | New Git URL