Encrypt, decrypt, and load .env files with authenticated AES-256-GCM encryption.
Project description
dotenv-encrypt
Encrypt, decrypt, edit, and load .env files from Python without committing
plaintext secrets.
dotenv-encrypt uses AES-256-GCM for authenticated encryption and derives keys
from a passphrase with scrypt. New files include a random salt, a random nonce,
and authenticated encryption metadata.
Install
pip install dotenv-encrypt
For local development:
python -m pip install -e ".[dev]"
pytest
Python Usage
from dotenv_encrypt import load_enc_env, unload_enc_env
load_enc_env(".env.enc", passphrase="your passphrase")
# os.environ now contains the variables from .env.enc
unload_enc_env()
Read and write encrypted dotenv files directly:
from dotenv_encrypt import read_encrypted_env, write_encrypted_env
write_encrypted_env(
{"API_KEY": "secret", "DEBUG": "false"},
".env.enc",
passphrase="your passphrase",
)
env = read_encrypted_env(".env.enc", passphrase="your passphrase")
CLI Usage
The CLI intentionally avoids passphrase command-line flags, because command-line
arguments can leak through shell history and process listings. Set
DOTENV_ENCRYPT_KEY for automation, or let the CLI prompt securely.
dotenv-encrypt encrypt .env -o .env.enc
dotenv-encrypt show .env.enc
dotenv-encrypt show .env.enc --values
dotenv-encrypt set API_KEY "secret" .env.enc
dotenv-encrypt unset API_KEY .env.enc
dotenv-encrypt merge .env.add .env.enc
dotenv-encrypt decrypt .env.enc -o .env.local
Security Notes
- Encryption is AES-256-GCM with a fresh 96-bit nonce for every write.
- Passphrases are stretched with scrypt and a fresh 128-bit salt per file.
- File metadata is authenticated with AES-GCM additional authenticated data.
- Output files are written with
0600permissions where the platform supports POSIX modes. - Secret values are not printed by default. Use
show --valuesonly when you explicitly need plaintext output. - The original script format is supported for decryption so existing
nonce || ciphertext || tagfiles can be migrated.
Publishing
Update the version in pyproject.toml, then build and check the package:
python -m build
python -m twine check dist/*
Upload with:
python -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dotenv_encrypt-0.1.0.tar.gz.
File metadata
- Download URL: dotenv_encrypt-0.1.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
031b564bb6a679594d5afd8b8467c1352b63c8493f06aab2e997fa61e0992d62
|
|
| MD5 |
e647c0112d4a8111a26a5b2755d2432f
|
|
| BLAKE2b-256 |
153e37fe640dd60172d958ab040708c5126f550ae327d9bac3f47fa4bba4dee8
|
Provenance
The following attestation bundles were made for dotenv_encrypt-0.1.0.tar.gz:
Publisher:
python-publish.yml on swiftbird07/dotenv-encrypt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenv_encrypt-0.1.0.tar.gz -
Subject digest:
031b564bb6a679594d5afd8b8467c1352b63c8493f06aab2e997fa61e0992d62 - Sigstore transparency entry: 1357021142
- Sigstore integration time:
-
Permalink:
swiftbird07/dotenv-encrypt@f64df3fa7ccd3b6178fb55d73eeb80d9b93f14f5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/swiftbird07
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f64df3fa7ccd3b6178fb55d73eeb80d9b93f14f5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file dotenv_encrypt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dotenv_encrypt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
feee0cd7c7cc8764a2eecf2587db0af9a5b27aa077122a981c371418e026c731
|
|
| MD5 |
13a58b8ed6aded999661d9691e6d10da
|
|
| BLAKE2b-256 |
9f29fa2c99bc2a0236265df802c5b84f0cb1292941bc1577affea9dca60b16ca
|
Provenance
The following attestation bundles were made for dotenv_encrypt-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on swiftbird07/dotenv-encrypt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenv_encrypt-0.1.0-py3-none-any.whl -
Subject digest:
feee0cd7c7cc8764a2eecf2587db0af9a5b27aa077122a981c371418e026c731 - Sigstore transparency entry: 1357021150
- Sigstore integration time:
-
Permalink:
swiftbird07/dotenv-encrypt@f64df3fa7ccd3b6178fb55d73eeb80d9b93f14f5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/swiftbird07
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f64df3fa7ccd3b6178fb55d73eeb80d9b93f14f5 -
Trigger Event:
workflow_dispatch
-
Statement type: