TurboEnv is a Python library that provides a simple and efficient way to manage environment variables in your applications. It allows you to easily load environment variables from .env files, access them in your code, and handle different environments (development, testing, production) with ease.
Python
0
38 commits
updated Oct 6, 2026
TurboEnv is a Python library that provides a simple and efficient way to manage environment variables in your applications. It allows you to easily load environment variables from .env files, access them in your code, and handle different environments (development, testing, production) with ease.
pip install turboenv
When load_envs is first called, it looks for any .env located in the absolute path of the file that is calling it. If it finds one, it loads the environment variables from that file in the default namespace.
from turboenv import TurboEnv
env = TurboEnv()
env.load_envs()
You can also specify the path to the .env file and the namespace you want to load it into.
from turboenv import TurboEnv
env = TurboEnv()
env.load_envs('path/to/.env')
env.string('DB_USER') # Accesses the DB_USER variable from the default namespace
Once the environment variables are loaded, you can access them in multiple different manners including typecasting their values to a specific one:
Tries to get the value of the environment variable with the given name. If the variable is not found, an exceptions.MissingEnvVariableError is raised.
db_user = env.get("DB_USER")
db_password = env.get("DB_PASSWORD")
Returns the boolean value of the environment variable with the given name:
db_password = env.boolean("USE_DB")
Returns the string value of the environment variable with the given name:
db_password = env.string("DB_PASSWORD")
Returns a list of strings by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_hosts = env.array("ALLOWED_HOSTS", cast=str)
Returns a list of strings by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_hosts = env.str_list("ALLOWED_HOSTS")
Returns a list of integers by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_ports = env.int_list("ALLOWED_PORTS")
Returns a list of domain names by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_domains = env.domain_list("ALLOWED_DOMAINS")
Returns a list of URLs by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_urls = env.url_list("ALLOWED_URLS")
Returns the value of the environment variable with the given name, decoded from base64:
db_password = env.secret("DB_PASSWORD")
[!NOTE] The secret value should already be encoded in base64 or this will raise an error.
Returns a Path object representing the path specified by the environment variable with the given name:
config_path = env.path("CONFIG_PATH")
Requires the value of the environment variable to be a valid URL.
url = env.url("WEBSITE_URL")
Requires the value of the environment variable to match a specified regular expression pattern.
match = env.regex("WEBSITE_URL", r"^https?://[^\s/$.?#].[^\s]*$")
[!ERROR] Error Will raise an error if the value does not match the specified regular expression pattern.
TurboEnv comes with a built-in class TurboEnvWithPresets that allows you to define and use preset environment variable configurations for different frameworks.
For example, in Django you can setup your STATIC_URL and MEDIA_URL environment by doing:
env = TurboEnv()
env.load_envs()
STATIC_URL = env.presets.django.static_url()
MEDIA_URL = env.presets.django.media_url()
Some special variables such as the ones provided below are provided since they are commonly used in various frameworks and services:
REDIS_URLAWS_S3_URLRABBITMQ_URLConditionals are used to guarantee the integrity of your environment variables by checking if they meet certain conditions. When the conditions are not met, an exception is raised.
Requires the presence of the specified environment variable in the environment.
env.conditional("DB_USER").depends_on(values=["DB_PASSWORD"])
[!CAUTION] It does not check the actual values of the environment variables, only their presence. Although the Turboenv does check for the presence of a variable if no default is provided, this check ensures that both
DB_USERandDB_PASSWORDare both present.
Requires the value of the environment variable to be equal to a specified value.
env.conditional("DB_USER").to_be("admin")
Requires the value of the environment variable to not be equal to a specified value.
env.conditional("DB_PASSWORD").not_to_be("password")
Requires the environment variable to be present.
[!CAUTION] This does not check if the value of the environment variable is empty or not, it only checks if it is present in the environment.
env.conditional("DB_USER").to_exist()
Requires the value of the environment variable to not be empty.
env.conditional("DB_PASSWORD").to_not_be_empty()
Requires the value of the environment variable to contain a specified substring.
env.conditional("ALLOWED_HOSTS").to_contain("example.com")
Requires the value of the environment variable to be a valid path that exists on the file system.
env.conditional("CONFIG_PATH").path_to_exist()
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or find any bugs.
To run the tests, use the following command:
pytest
This project is licensed under the MIT License. See the LICENSE file for more details.
TurboEnv is a Python library that provides a simple and efficient way to manage environment variables in your applications. It allows you to easily load environment variables from .env files, access them in your code, and handle different environments (development, testing, production) with ease.
Python
0
38 commits
updated Oct 6, 2026
TurboEnv is a Python library that provides a simple and efficient way to manage environment variables in your applications. It allows you to easily load environment variables from .env files, access them in your code, and handle different environments (development, testing, production) with ease.
pip install turboenv
When load_envs is first called, it looks for any .env located in the absolute path of the file that is calling it. If it finds one, it loads the environment variables from that file in the default namespace.
from turboenv import TurboEnv
env = TurboEnv()
env.load_envs()
You can also specify the path to the .env file and the namespace you want to load it into.
from turboenv import TurboEnv
env = TurboEnv()
env.load_envs('path/to/.env')
env.string('DB_USER') # Accesses the DB_USER variable from the default namespace
Once the environment variables are loaded, you can access them in multiple different manners including typecasting their values to a specific one:
Tries to get the value of the environment variable with the given name. If the variable is not found, an exceptions.MissingEnvVariableError is raised.
db_user = env.get("DB_USER")
db_password = env.get("DB_PASSWORD")
Returns the boolean value of the environment variable with the given name:
db_password = env.boolean("USE_DB")
Returns the string value of the environment variable with the given name:
db_password = env.string("DB_PASSWORD")
Returns a list of strings by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_hosts = env.array("ALLOWED_HOSTS", cast=str)
Returns a list of strings by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_hosts = env.str_list("ALLOWED_HOSTS")
Returns a list of integers by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_ports = env.int_list("ALLOWED_PORTS")
Returns a list of domain names by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_domains = env.domain_list("ALLOWED_DOMAINS")
Returns a list of URLs by splitting the value of the environment variable with the given name using a specified separator (default is comma):
allowed_urls = env.url_list("ALLOWED_URLS")
Returns the value of the environment variable with the given name, decoded from base64:
db_password = env.secret("DB_PASSWORD")
[!NOTE] The secret value should already be encoded in base64 or this will raise an error.
Returns a Path object representing the path specified by the environment variable with the given name:
config_path = env.path("CONFIG_PATH")
Requires the value of the environment variable to be a valid URL.
url = env.url("WEBSITE_URL")
Requires the value of the environment variable to match a specified regular expression pattern.
match = env.regex("WEBSITE_URL", r"^https?://[^\s/$.?#].[^\s]*$")
[!ERROR] Error Will raise an error if the value does not match the specified regular expression pattern.
TurboEnv comes with a built-in class TurboEnvWithPresets that allows you to define and use preset environment variable configurations for different frameworks.
For example, in Django you can setup your STATIC_URL and MEDIA_URL environment by doing:
env = TurboEnv()
env.load_envs()
STATIC_URL = env.presets.django.static_url()
MEDIA_URL = env.presets.django.media_url()
Some special variables such as the ones provided below are provided since they are commonly used in various frameworks and services:
REDIS_URLAWS_S3_URLRABBITMQ_URLConditionals are used to guarantee the integrity of your environment variables by checking if they meet certain conditions. When the conditions are not met, an exception is raised.
Requires the presence of the specified environment variable in the environment.
env.conditional("DB_USER").depends_on(values=["DB_PASSWORD"])
[!CAUTION] It does not check the actual values of the environment variables, only their presence. Although the Turboenv does check for the presence of a variable if no default is provided, this check ensures that both
DB_USERandDB_PASSWORDare both present.
Requires the value of the environment variable to be equal to a specified value.
env.conditional("DB_USER").to_be("admin")
Requires the value of the environment variable to not be equal to a specified value.
env.conditional("DB_PASSWORD").not_to_be("password")
Requires the environment variable to be present.
[!CAUTION] This does not check if the value of the environment variable is empty or not, it only checks if it is present in the environment.
env.conditional("DB_USER").to_exist()
Requires the value of the environment variable to not be empty.
env.conditional("DB_PASSWORD").to_not_be_empty()
Requires the value of the environment variable to contain a specified substring.
env.conditional("ALLOWED_HOSTS").to_contain("example.com")
Requires the value of the environment variable to be a valid path that exists on the file system.
env.conditional("CONFIG_PATH").path_to_exist()
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or find any bugs.
To run the tests, use the following command:
pytest
This project is licensed under the MIT License. See the LICENSE file for more details.