Skip to content

Allow configuring env letter case rules for settings parser #277

@jasonkuhrt

Description

@jasonkuhrt

Issue derived from #275

Currently BaseSettings defaults to looking for env variables in uppercase. This issue is a feature proposal to make this behaviour configurable.

The current workaround is to use the settings config class to set up aliases, e.g.:

 class S(pydantic.BaseSettings):
      test:str

      class Config:
          fields = dict(test=dict(alias="test"))

However this is verbose and onerous to do (for the developer), if there are many such env vars.

It would be nice if the developer could do something like:

 class S(pydantic.BaseSettings):
      class Config:
          letter_case = "lower" # or:  "upper" | "any"

      test:str

About this concern raised for case insensitive option #275 (comment).

  • we could log a warning or raise an error at a certain configurable threshold of
    • env var count
    • or perhaps based on measured processing time exceeding configurable budget (e.g. 1ms)
  • we could cache the calculation of env2 (but probably the entire settings result would just be cached by the app)
  • the env prefix could help reduce the amount of work needed to do

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions