Skip to main content

Parsing configuration from environment variables as typing.NamedTuple

Project description

This project allows you to describe the configuration of your application as a typing.NamedTuple, like so:

import typing

class MyAppConfig(typing.NamedTuple):
    some_string: str
    some_int: int
    some_float: float
    some_bool: bool = True

Then, gather the configuration from the environment variables:

import env_var_config

config = env_var_config.gather_config_for_class(MyAppConfig)

The code will look for variables that are called like the fields of the tuple, but uppercase.

As you might have noticed, you can set default values on the fields. If the fields with defaults are not found in the environment, they’re set to their default value (which is quite unsurprising). If a value without a default is missing, though, an error will be raised. That is, unless you set allow_empty option to True in the call to gather_config_for_class. Then all missing values will be initialized with the default value for their type, such as an empty string for str, 0 for int, etc.

Installation

pip install env_var_config

Project details


Download files

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

Files for env-var-config, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size env_var_config-0.1.0-py3-none-any.whl (3.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size env_var_config-0.1.0.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page