Is it possible to override specific model_config settings on instantiation?

98 Views Asked by At

This is my class

class MyConfig(BaseSettings):
    model_config = SettingsConfigDict(
        env_file="myconf.env",
        # extra="allow",
    )
    ...

I want to be able to do something like this MyConfig({"some":"dict"}, extra="allow" to dynamically set some SettingsConfigDict settings at the time of instantiation.

I could not figure out how to do this because I'm not going to override and reimplement BaseSettings's __init__ method. Is there support for overriding only some model_config settings when creating a new instance?

I am aware of this: https://docs.pydantic.dev/latest/concepts/config/#change-behaviour-globally. But I don't want to have to create a separate subclass for every specific setting- I want to set that dynamically when the class is created.

0

There are 0 best solutions below