Skip to content

Easily list the names of the env var required to set a field #292

Closed
@sotte

Description

@sotte

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions