pydantic-cli
pydantic-cli copied to clipboard
Cli support nested params
Hi. In my scenario, I has a nested model of pydantic:
class B(BaseModel):
name: str
class A(BaseModel):
b: B
class Wrapper(BaseModel):
class Config(DefaultConfig):
CLI_JSON_ENABLE = True
a: A
I can pass the args from json file by "--json-config":
{
a: {
b: {
"name": "test"
}
}
}
But I won't pass a nested args in command line likemy-cli --a.b.name test
I want to ask that is it possible to support this feature?
Thank you very much.
The lack of nested model support is a core design decision.
https://github.com/mpkocher/pydantic-cli#limitations
I think you might be better suited by a more dictionary munging centric library.
Perhaps a library that has an interface like this that does some minimal json munging/loading and then passes the raw dict to pydantic for validation.
my-tool -o a.b.name=test --option a.b.max=10 --json-config=my-config.json
This is probably easily doable with a minimal amount of code with a thin layer around argparse.
However, it's not something that I'm interested in supporting in pydantic-cli
.
Thanks for your feedback.
Here's a list of other projects that might be more aligned with your project's requirements.
https://github.com/mpkocher/pydantic-cli#other-related-tools
Best of luck to you on your future projects.
The lack of nested model support is a core design decision.
https://github.com/mpkocher/pydantic-cli#limitations
I think you might be better suited by a more dictionary munging centric library.
Perhaps a library that has an interface like this that does some minimal json munging/loading and then passes the raw dict to pydantic for validation.
my-tool -o a.b.name=test --option a.b.max=10 --json-config=my-config.json
This is probably easily doable with a minimal amount of code with a thin layer around argparse.
However, it's not something that I'm interested in supporting in
pydantic-cli
.Thanks for your feedback.
Here's a list of other projects that might be more aligned with your project's requirements.
https://github.com/mpkocher/pydantic-cli#other-related-tools
Best of luck to you on your future projects.
Thank your advice very much. I would consider that modify my code. pydantic-cli is a fantastic library 👍🏻.
Hi. In my scenario, I has a nested model of pydantic:
class B(BaseModel): name: str class A(BaseModel): b: B class Wrapper(BaseModel): class Config(DefaultConfig): CLI_JSON_ENABLE = True a: A
I can pass the args from json file by "--json-config":
{ a: { b: { "name": "test" } } }
But I won't pass a nested args in command line like
my-cli --a.b.name test
I want to ask that is it possible to support this feature?
Thank you very much.
Pydantic Settings has support for this and might be more aligned with your requirements.
https://docs.pydantic.dev/latest/concepts/pydantic_settings/#command-line-support
Thanks for your feedback.