Skip to main content

Simple dotenv loader with the possibility of casting types

Project description

Dotenv config

Simple .env config loader with type casting.

Build Status Coverage Status Python versions PyPi


pip3 install dotenv-config  # or pip if python3 is your default interpreter


All you need is instantiate the Config class. As an optional argument you can specify the path to your config file, by default this is .env

from dotenv_config import Config

config = Config('.env-test')

To read the configuration, call the Config instance. By default the returned value is a string.

some_str_option = config('SOME_OPTION_FROM_YOUR_ENV_FILE_OR_ENVIRONMENT')  # str

To cast a type, any callable object can be passed as second argument or conversion. As an argument, it must accept the value read from the config and return the result of type casting. For example, if you have SOME_INT=123 in your .env and need to load it as int, call config like this:

int_option = config('SOME_INT', int)
# or
int_option = config('SOME_INT', conversion=int)

You can perform a cast to boolean if the option is specified in the config as 0 or 1. For example, if you have a TRUE_OPTION=1 and FALSE_OPTION=0:

true_option = config('TRUE_OPTION', bool)  # True
false_option = config('FALSE_OPTION', bool)  # false

Also, you can specify a default value for situations when the requested option may not be:

some_value = config('SOME_VALUE', default='my english is bad')

If the requested option does not exist and the default value is not specified, an ConfigValueNotFound exception will be raised.

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 dotenv-config, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size dotenv-config-0.1.4.tar.gz (2.3 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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page