[FEATURE] support Pydantic BaseModel to "collect" all kwargs, like FastAPI #679
Unanswered
odoublewen
asked this question in
Questions
Replies: 3 comments 2 replies
-
This works for me: @app.command()
class foo_cmd(BaseModel):
"""foo cmd"""
x: int
y: bool = False
def model_post_init(self, _):
print(f"{self.x=}, {self.y=}") |
Beta Was this translation helpful? Give feedback.
2 replies
-
also, name argument to |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ahh, that's what I'm got about parameter names.
and now we get a nice help:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I might be missing something, but wouldn't it be cool if Typer could work like this FastAPI docs example.
This feature request superficially resembles #111 but notice I'm seeking to use a Pydantic
BaseModel
as THE input for the function, not just as a custom type for one of many args.I struggled to write a descriptive title that would differentiate it from this other request (which is also well reasoned I think). I think the example code makes it clear what I'm thinking of.
Operating System
Linux, macOS
Operating System Details
No response
Typer Version
0.9.0
Python Version
Python 3.10.11
Additional Context
I love Typer, thanks!
Beta Was this translation helpful? Give feedback.
All reactions