Skip to main content

OneEnv: Environment variable management and generation tool

Project description

OneEnv 🌟

OneEnv is an environment variable management and generation tool for Python applications. It wraps python-dotenv to simplify handling of environment variable templates and .env files.

What Problems Does OneEnv Solve? 🛠️

Managing environment variables for multiple libraries can be tedious and error-prone, especially when each library requires its own configuration. OneEnv streamlines the process by consolidating environment variable templates into a single .env.example file, reducing manual work and ensuring consistency across projects.

Features 🚀

  • Template Collection: Use the @oneenv decorator to declare environment variable templates.
  • Generated .env.example: Automatically creates a consolidated .env.example file from registered templates.
  • Diff Functionality: Compare changes between different versions of your .env.example file.
  • Duplicate Key Detection: Identify duplicate environment variable definitions across modules.
  • Command Line Tool: Easily run commands like oneenv template and oneenv diff from your terminal.

Supported Environments 🖥️

  • Python: ≥ 3.11
  • Operating Systems: Windows, macOS, Linux

Installation 📦

You can install OneEnv easily via pip:

pip install oneenv

For development mode, install from the source using:

pip install -e .

Usage 🚀

Generating Environment Template

Generate a consolidated .env.example file using the registered templates:

oneenv template [-o OUTPUT_FILE]

Comparing Environment Files

Compare two .env files to see what has changed:

oneenv diff previous.env current.env

Example: Using the @oneenv Decorator

Below is an example of how to use the @oneenv decorator in your code:

from oneenv import oneenv

@oneenv
def my_env_template():
    return {
        "MY_API_KEY": {
            "description": "API key for accessing the service.",
            "default": "",
            "required": True,
            "choices": []
        },
        "MODE": {
            "description": "Application mode setting.",
            "default": "development",
            "required": False,
            "choices": ["development", "production"]
        }
    }

Place the above code within your library or application to automatically register environment variable templates.

Note: It is sufficient to only provide the description attribute in your template. Other attributes such as default, required, and choices are optional.

Minimal Example: Using Only description

If you prefer the simplest setup, you can provide only the description attribute. For example:

from oneenv import oneenv

@oneenv
def minimal_template():
    return {
        "SIMPLE_VAR": {
            "description": "A simple environment variable."
        }
    }

This minimal example works perfectly and emphasizes the ease of use. Additionally, since OneEnv is a wrapper around python-dotenv, it can also be used like dotenv to load environment variables.

Dotenv Integration 🔄

OneEnv is more than just an environment template generator. Being a wrapper around python-dotenv, it also allows you to seamlessly load environment variables into your application.

Example: Loading Environment Variables Using OneEnv

You can use OneEnv to load environment variables from a .env file just like you would with python-dotenv:

from oneenv import load_dotenv, dotenv_values

# Load environment variables into the current process
load_dotenv()

# Alternatively, get them as a dictionary
env_vars = dotenv_values(".env")
print(env_vars)

The integration allows you to manage your environment variables in one centralized place while benefiting from all the features of python-dotenv.

Running Tests 🧪

Make sure your virtual environment is active, then run:

pytest tests

Contributing 🤝

Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.

License ⚖️

This project is licensed under the MIT License.

Project details


Download files

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

Source Distribution

oneenv-0.1.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oneenv-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file oneenv-0.1.1.tar.gz.

File metadata

  • Download URL: oneenv-0.1.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for oneenv-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c324b4bfe9d4e7ec6aa0348cc5e560427070cab9eddb2d65ba28a1c8a074bdcd
MD5 a4439f984c4bed3204846ba5a3857206
BLAKE2b-256 2722b3388ca7330e43a5ec129f688864f8c6cadc70343bf8ba30106a5cfe4742

See more details on using hashes here.

File details

Details for the file oneenv-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: oneenv-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for oneenv-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30b508e76258d771a484a18632b6dcb30cd755b50e553f462692992c63d2e527
MD5 18f87575757f9a3f8e9784608193acf0
BLAKE2b-256 d76e4b89caad094c913c610deaaea8a7a0b2639144e4998fbe84b4e83cca7f55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page