Skip to main content

A tool to manage encrypted environment variables.

Project description

EnvVault

EnvVault is a Python package for encrypting and managing .env files, similar to Rails Credentials. It allows you to securely store sensitive information (such as API keys, database passwords, etc.) and decrypt and use this information at runtime.

Features

  • Encrypt .env files: Encrypt plaintext .env files into .env.enc files.
  • Decrypt .env.enc files: Decrypt .env.enc files at runtime and load environment variables.
  • Multi-environment support: Create separate encrypted files for different environments (e.g., development, production).
  • Dynamic field support: Automatically define fields in Settings based on the contents of .env.enc.
  • Type inference: Automatically infer field types (e.g., str, int, bool) from environment variable values.
  • CLI tool: Provides a command-line interface for managing encrypted files.
  • Integration with pydantic_settings: Supports managing decrypted environment variables using pydantic_settings.

Dynamic Field Support

EnvVault dynamically creates Settings fields based on the contents of the .env.enc file. For example, if your .env.enc file contains:

API_KEY=your_api_key_here
DATABASE_URL=your_database_url_here
DEBUG=true
PORT=8080

EnvVault will automatically create the following fields in the Settings class:

  • API_KEY (string)
  • DATABASE_URL (string)
  • DEBUG (boolean)
  • PORT (integer)

Type Inference

EnvVault supports automatic type inference for environment variables. For example:

  • DEBUG=trueDEBUG is inferred as a boolean.
  • PORT=8080PORT is inferred as an integer.
  • API_KEY=your_api_key_hereAPI_KEY is inferred as a string.

Installation

Install using Poetry:

poetry add envvault

# Or install using pip:
pip install envvault

Usage

1. Initialize

Initialize the master key and an empty .env.enc file:

envvault init --env development

This will generate the following files:

  • master.key: The master key used for encryption and decryption.
  • .env.development.enc: An empty encrypted file.

2. Edit Encrypted File

Edit the .env.enc file using your default editor:

envvault edit --env development

The editor will open a temporary file. After editing, the content will be re-encrypted and saved to .env.development.enc.


3. View Decrypted Environment Variables

Decrypt and view the contents of the .env.enc file:

envvault view --env development

Enter the following content in the editor:

API_KEY=your_api_key_here
DATABASE_URL=your_database_url_here
DEBUG=true
PORT=8080

4. Regenerate master.key

Regenerate the master key for the development environment:

envvault rekey --env development

5. Use in Code

Load decrypted environment variables in your code:

from envvault.settings import Settings

# Load configuration for the development environment
settings = Settings.from_credentials(env_name="development")
print("API Key:", settings.API_KEY)
print("Database URL:", settings.DATABASE_URL)

or

from envvault.settings import get_settings

# Load configuration for the current environment
envvault = get_settings()
print("API Key:", envvault.API_KEY)
print("Database URL:", envvault.DATABASE_URL)

Configuration

Default Editor

You can set the default editor using the EDITOR environment variable. For example:

export EDITOR=code  # Use VS Code
export EDITOR=nano  # Use Nano
export EDITOR=vim   # Use Vim

Multi-Environment Support

EnvVault supports creating separate encrypted files for different environments. For example:

  • .env.development.enc: Development environment.
  • .env.enc: Production environment.

Specify the environment name using the --env parameter in CLI commands.


Contributing

Issues and Pull Requests are welcome!


License

MIT

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

envvault-0.1.5.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

envvault-0.1.5-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file envvault-0.1.5.tar.gz.

File metadata

  • Download URL: envvault-0.1.5.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for envvault-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9a55e64767e0a0251a11dbc6a8ad05aaceb63802ebad0a9fb2e885922a1f5025
MD5 7da26ec43a6b50a7c0c8b6027a482086
BLAKE2b-256 3485502c8a9d2dabf4b7ac9db7c194c131dcd8da9f0f45c6a57bebde4f666fff

See more details on using hashes here.

File details

Details for the file envvault-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: envvault-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for envvault-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4ef9d50ee255b259d86ed86efbfd515ff913bb89cd9695ed3d430dd094cc636b
MD5 e6fbabf4655880ec1d5ed88bcfd3a1fb
BLAKE2b-256 0364a3e2889fb0fe4dfa8ae25f01f44796067d7ffa1a523234e8359ccf7978d6

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