-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support of pydantic to use in structured config #420
Comments
Hi @espdev, In terms of more powerful validation, take a look at #131. |
Got it. Thanks! In my some projects I use OmegaConf and pydantic together. OmegaConf loads config files and performs interpolation. pydantic model represents a typed config structure and validates config dictionary after |
In terms of config composition: |
Yes, I know about Hydra. However, Hydra is a high-level solution with a focus to app-oriented projects with complex configuration. In one of the future cli-based app project I would like to use Hydra. With pydantic model based configs I have statically defined config objects. IDE knows about it: auto-completion and type checking work fine. And pydantic allows me to define more config value types: |
Yup, Hydra is higher level. I wanted to understand how you are using OmegaConf better. @dataclass
class User:
age: int
name: str
user : User = OmegaConf.structured(User(age=7, name="bond")) OmegaConf adds runtime type safety in addition to static type safety: user.age = "seven" # Validation exception at runtime. This type safety extends to config merges as well with somewhat different semantics. |
Thanks for your explanation and recommendations! I will take a look. Maybe I can really do without pydantic. |
@espdev could you share what have you learned wrt to this topic in the last ~6 months? I'm also facing this decision, whether to let go on |
there is also https://pydantic-docs.helpmanual.io/usage/dataclasses/ this might serve to add some pydantic features while still being omegaconf compatible. I may try this with a project I'm currently working on, I'll try and remember to report back any findings. |
I seem to recall that I tried OmegaConf+Pydantic at some point and that it worked. |
Currently, omegaconf supports dataclasses to create structured configs.
Pydantic is a library for Python 3.6+ for data parsing and validation using Python type hints.
Would you mind considering support of pydantic BaseModel/BaseSettings for structured configs? Using pydantic would allow to shift the parsing/validation functionality to it and supporting a lot of data types in configs (IP addresses, URLs, email, Path etc).
The text was updated successfully, but these errors were encountered: