Closed
Description
Is there an easy way to get/print the name of the env var that is used to set the value of a field?
Problem:
You have a bunch of configs (potentially nested) and you quickly want to know what the name of the env var for a given field is.
Current workaround:
Right now, I read the code, the nesting of the models, and the SettingsConfigDict
to infer the name of the field. Then I try names until I find the correct one.
Potential solution:
Add a new function like print_env_var_names()
that works something like this:
class MyModel(
class MyModel(BaseSettings):
model_config = SettingsConfigDict(env_prefix='FOO__')
bar: int=5
print_env_var_names(MyModel)
# MyModel.bar -> FOO__BAR