Skip to main content

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=true → DEBUG is inferred as a boolean.
  • PORT=8080 → PORT is inferred as an integer.
  • API_KEY=your_api_key_here → API_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

Master Key Retrieval

EnvVault retrieves the master key value first from the MASTER_KEY environment variable, and if not found, from the master.key file. This allows for flexibility in managing the master key.


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

Metadata

Release files for envvault 0.1.7

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

Source distribution (sdist)

Source distribution for envvault 0.1.7
File Size Uploaded
envvault-0.1.7.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envvault 0.1.7
File Interpreter ABI Platform
envvault-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / envvault-0.1.7.tar.gz

Download URL envvault-0.1.7.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
57eb3632025ff62c19246e9931718a332cdb88f28557d9eafa5c0bf99947c7c6
BLAKE2b-256 checksum
How to use checksums
47589dc9be663b95f22f7a05490d93ede3b04d9ad8f6670fc2d7733a77a2d856
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / envvault-0.1.7-py3-none-any.whl

Download URL envvault-0.1.7-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1032927fece4f4161e77509e9f4d8427f2aaadb8b1eac8513e97d9435d643393
BLAKE2b-256 checksum
How to use checksums
109b08ad1e410c10856c3793ad93088482cc0865496ef0375cc16283b82039e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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