This Python package provides an easy way to interact with environment variables in your Python applications. It is designed to simplify the process of loading and parsing various data types from environment variables.
- Auto load environment variables from .env files based on application environment (
devortest). - Provide easy-to-use functions to access environment variables with type hinting.
- Support different data types including strings, lists, dictionaries, integers and booleans.
- Allow defaults for environment variables.
- Provide decorator
@depends_on_envfor user-defined functions to ensure environment variables are loaded.
Install the package from PyPi using pip:
pip install envutilImport the package in your Python code as follows:
from envutil import env_str, env_csv, env_int, env_bool, env_list, env_dictAccess your environment variables:
# Access string variable
my_var = env_str('MY_VAR', default='default-value')
# Access comma separated value as a list
my_csv = env_csv('MY_CSV', default=[])
# Access integer variable
my_int = env_int('MY_INT', default=0)
# Access boolean variable
my_bool = env_bool('MY_BOOL', default=False)
# Access list variable
my_list = env_list('MY_LIST', default=[])
# Access dictionary variable
my_dict = env_dict('MY_DICT', default={})By default, this package loads .env file. If the APP_ENV is set to test, it will load .env.test file. You can also specify a custom environment file by setting the APP_ENV_FILE environment variable.
Your contributions are always welcome! Please have a look at the contribution guidelines first. 🎉
This package is released under the MIT License.