New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring env letter case rules for settings parser #277

Closed
jasonkuhrt opened this Issue Oct 16, 2018 · 1 comment

Comments

2 participants
@jasonkuhrt
Contributor

jasonkuhrt commented Oct 16, 2018

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
@samuelcolvin

This comment has been minimized.

Owner

samuelcolvin commented Oct 16, 2018

I think just a warning in the docs is enough for the size thing.

jasonkuhrt added a commit to jasonkuhrt/pydantic that referenced this issue Nov 25, 2018

samuelcolvin added a commit that referenced this issue Nov 26, 2018

feat: add support for case insensitive env names (#313)
* feat: add support for case insensitive env names

Closes #277

* feedback: just alias os.environ

* doc: update history

* doc: mention case_insensitive option

* refactor: feedback if-else expression assignment

* fix: formatting

* chore: encode black configuration in file to support IDEs

* docs: fix example

* feedback: no suppport for IDEs in this PR

* feedback: style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment