Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Turbo Env

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.

Installation

pip install turboenv

Loading Environment variables

Automatic detection

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

Accessing Environment Variables

Once the environment variables are loaded, you can access them in multiple different manners including typecasting their values to a specific one:

Get method

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")

Boolean - Type Casting

Returns the boolean value of the environment variable with the given name:

db_password = env.boolean("USE_DB")

String - Type Casting

Returns the string value of the environment variable with the given name:

db_password = env.string("DB_PASSWORD")

Array - Type Casting

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)

String List - Type Casting

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")

Integer List - Type Casting

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")

Domain List - Type Casting

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")

URL List - Type Casting

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")

Secret - Type Casting

Returns the value of the environment variable with the given name, decoded from base64:

db_password = env.secret("DB_PASSWORD")

Path - Type Casting

Returns a Path object representing the path specified by the environment variable with the given name:

config_path = env.path("CONFIG_PATH")

Url

Requires the value of the environment variable to be a valid URL.

url = env.url("WEBSITE_URL")

Regex

Requires the value of the environment variable to match a specified regular expression pattern.

match = env.regex("WEBSITE_URL", r"^https?://[^\s/$.?#].[^\s]*$")

[!ERROR] Will raise an error if the value does not match the specified regular expression pattern.

Working with a framework

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 = TurboEnvWithPresets()
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_URL
  • AWS_S3_URL
  • RABBITMQ_URL

Conditionals

Conditionals 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.

Depends On

Requires the presence of the specified environment variable in the environment.

env.conditional("DB_USER").depends_on(values=["DB_PASSWORD"])

To Be

Requires the value of the environment variable to be equal to a specified value.

env.conditional("DB_USER").to_be("admin")

Not To Be

Requires the value of the environment variable to not be equal to a specified value.

env.conditional("DB_PASSWORD").not_to_be("password")

To Exist

Requires the environment variable to be present.

env.conditional("DB_USER").to_exist()

To Not Be Empty

Requires the value of the environment variable to not be empty.

env.conditional("DB_PASSWORD").to_not_be_empty()

To Contain

Requires the value of the environment variable to contain a specified substring.

env.conditional("ALLOWED_HOSTS").to_contain("example.com")

Path To Exist

Requires the value of the environment variable to be a valid path that exists in the file system.

env.conditional("CONFIG_PATH").path_to_exist()

Contributing

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

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Metadata

Release files for turboenv 0.2.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for turboenv 0.2.0a3
File Size Uploaded Provenance Actions
turboenv-0.2.0a3.tar.gz 11.6 kB Without provenance Details for turboenv-0.2.0a3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for turboenv 0.2.0a3
File Interpreter ABI Platform Actions
turboenv-0.2.0a3-py3-none-any.whl Python 3 none any Details for turboenv-0.2.0a3-py3-none-any.whl

Total release size: 24.9 kB

Release files / turboenv-0.2.0a3.tar.gz

Download URL turboenv-0.2.0a3.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
507fa62aadf17f8ffc9bab07de7687eea869e327d833413ecfec954683d27e22
BLAKE2b-256 checksum
How to use checksums
f045a1d0ae7b7076bbd9c91d74264ace463f45654e42a9b70d174faaacffdc05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / turboenv-0.2.0a3-py3-none-any.whl

Download URL turboenv-0.2.0a3-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4f09e3663cd9b75ccf785e13b6a1cceaf114003e745c34cc0b0e0b645b7198a
BLAKE2b-256 checksum
How to use checksums
7a0e7a4d3d0cf8d1f585999211aa6b19a0e84b93877b537902ba5adafdb4629c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for turboenv 0.2.0a3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page