Skip to main content

Pydantic BaseSettings Explicit

Project description

Pydantic Env Settings

Wrapper around BaseSettings.

Sets the usage of the .env file as default.

Modifies the error description while parsing .env file:

  • marks it is a settings validation error
  • renames the field names by adding the env_prefix and uppercaseing it
  • gives hint about .env file

Installation

Using pip:

pip install pydantic-env-settings

Usage

class MySettings(EnvSettings):
    filename: str
    verbose: bool

    class Config:
        env_prefix = 'MY_'

settings = MySettings()

print(settings.filename)
print(settings.verbose)

Then your .env file should contain:

MY_FILENAME = /tmp/tempfile.bin
MY_VERBOSE = true

If your .env file does not exists or you have type errors in it you will see an error message like:

SettingsError: 2 validation errors for MySettings
MY_FILENAME
  field required (type=value_error.missing)
MY_VERBOSE
  field required (type=value_error.missing)

Hint! Verify your environment setting or the '.env' file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_env_settings-0.1.1.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

pydantic_env_settings-0.1.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page