EnvCrypt Library

EnvCrypt is a Python library designed for managing encrypted environment files. It supports multiple encryption methods, including Base64 and AES, and allows for easy switching between different environments.

Features

  • Support for Base64 and AES encryption.
  • Environment switching (development, production, etc.).
  • File integrity verification via SHA-256 hashing.
  • Automatic backups before any changes.
  • Easy access and modification of environment variables.

Usage

To use EnvCrypt, simply import the library and initialize it:


from envcrypt import Env

env = Env("path/to/envfile", encryption_method="AES")
api_key = env.get("API_KEY")
            

Installation

To install EnvCrypt, use the following command:


pip install envcrypt
            

API Reference

get(name)

Retrieve the value of the specified environment variable.


env.get("VARIABLE_NAME")
            

pop(name)

Remove the specified environment variable and update the file.


env.pop("VARIABLE_NAME")
            

setdefault(name, value)

Set a default value for the environment variable if it does not exist, and update the file.


env.setdefault("VARIABLE_NAME", "default_value")
            

switch_environment(environment_name)

Switch the current environment to the specified one.


env.switch_environment("development")
            

verify_integrity()

Verify the integrity of the environment file using SHA-256 hash.


env.verify_integrity()
            

list_env()

List all environment variables in the current environment.


env.list_env()