I am trying to load a yml file into a dict, with pyyaml, theloading process automatically loads proper types for me, e.g., yml file with content below:
key1: test
key2: 100
will be loaded into a dict of {"key1": "test", "key2":100} where the type of key1's value is string, and the type of key2's value is int.
Now I want to dynamically create a class based on this dict, basically a class that has the dict keys as fields and dict values as values as shown below:
class Test:
key1: str = "test"
key2: int = 100
I believe I can do something like below using Pydantic:
Test = create_model('Test', key1=(str, "test"), key2=(int, 100))
However, as shown here, I have to manually tell create_model what keys and types for creating this model. I wonder if there is a away to automatically use the items in the dict to create model?