Python bindings for dotenvage - encrypt secrets in .env files using age encryption
Project description
dotenvage
Python bindings for
dotenvage — encrypt
secrets in .env files using age encryption (X25519).
Installation
pip install dotenvage
# or with uv
uv add dotenvage
Quick start
import dotenvage
# Generate a new identity (key pair)
manager = dotenvage.SecretManager.generate()
print(f"Public key: {manager.public_key_string()}")
# Encrypt a secret
encrypted = manager.encrypt_value("my-secret-password")
print(f"Encrypted: {encrypted}")
# Output: ENC[AGE:b64:...]
# Decrypt it back
decrypted = manager.decrypt_value(encrypted)
print(f"Decrypted: {decrypted}")
# Output: my-secret-password
# Check if a value is encrypted
print(dotenvage.SecretManager.is_encrypted(encrypted)) # True
print(dotenvage.SecretManager.is_encrypted("plain")) # False
Loading .env files
import dotenvage
# Load .env files (decrypts encrypted values automatically)
loader = dotenvage.EnvLoader()
loaded_files = loader.load()
print(f"Loaded: {loaded_files}")
# Or get all variables as a dict
variables = loader.get_all_variables()
print(variables)
Auto-detection
dotenvage can detect which keys should be encrypted based on naming patterns:
import dotenvage
# Keys containing PASSWORD, SECRET, KEY, TOKEN, etc. are detected
dotenvage.should_encrypt("API_KEY") # True
dotenvage.should_encrypt("DATABASE_URL") # False
dotenvage.should_encrypt("SECRET_TOKEN") # True
Key discovery
The SecretManager automatically discovers keys in this order:
- Auto-discover
AGE_KEY_NAMEfrom.envor.env.localfiles DOTENVAGE_AGE_KEYenvironment variable (full identity string)AGE_KEYenvironment variableEKG_AGE_KEYenvironment variable- OS keychain entry (service:
dotenvageorDOTENVAGE_KEYCHAIN_SERVICE; account:AGE_KEY_NAMEor{CARGO_PKG_NAME}/dotenvage) - Key file from
AGE_KEY_NAME→~/.local/state/{namespace}/{keyname}.key - Default:
~/.local/state/dotenvage/dotenvage.key
OS keychain lookup currently uses:
- macOS: Keychain via
security - Linux/Unix: Secret Service via
secret-tool - Windows: lookup falls back to file/env sources (no keychain lookup yet);
keygen --store os|bothstores usingcmdkey
AGE_KEY_NAME format is {namespace}/{keyname}, e.g., myapp/production
→ ~/.local/state/myapp/production.key
API reference
SecretManager
Manager for encrypting and decrypting secrets using age encryption.
class SecretManager:
def __init__(self) -> None:
"""Create from discovered key file."""
@staticmethod
def generate() -> SecretManager:
"""Generate a new random identity (key pair)."""
@staticmethod
def from_identity_string(identity: str) -> SecretManager:
"""Create from an age identity string (AGE-SECRET-KEY-...)."""
@staticmethod
def is_encrypted(value: str) -> bool:
"""Check if a value is in encrypted format."""
def public_key_string(self) -> str:
"""Get public key as age1... string."""
def encrypt_value(self, plaintext: str) -> str:
"""Encrypt to ENC[AGE:b64:...] format."""
def decrypt_value(self, value: str) -> str:
"""Decrypt if encrypted, otherwise return unchanged."""
EnvLoader
Loader for .env files with automatic decryption.
class EnvLoader:
def __init__(self) -> None:
"""Create with default SecretManager."""
@staticmethod
def with_manager(manager: SecretManager) -> EnvLoader:
"""Create with a specific SecretManager."""
def load(self) -> list[str]:
"""Load .env files from current directory. Returns loaded paths."""
def load_from_dir(self, dir: str) -> list[str]:
"""Load .env files from specific directory."""
def get_all_variable_names(self) -> list[str]:
"""Get all variable names from .env files."""
def get_all_variable_names_from_dir(self, dir: str) -> list[str]:
"""Get all variable names from .env files in directory."""
def get_all_variables(self) -> dict[str, str]:
"""Load and return all variables as dict (decrypted)."""
def get_all_variables_from_dir(self, dir: str) -> dict[str, str]:
"""Load and return all variables from directory (decrypted)."""
def resolve_env_paths(self, dir: str) -> list[str]:
"""Get ordered list of .env file paths that would be loaded."""
Functions
def should_encrypt(key: str) -> bool:
"""Check if key name should be encrypted based on patterns."""
License
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 Distributions
Built Distributions
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 dotenvage-0.6.2-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: dotenvage-0.6.2-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 563.4 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95ab59c8cd49c8b0045cabda448511028c4cf36fabe2d92cfe357bab1b3c6547
|
|
| MD5 |
ff545358cd6e0bd1ef3c7ff1fe583570
|
|
| BLAKE2b-256 |
85f3b34b7b440623c46f2cfad83d280cd3cc9bc5cac6ceb1b22658bccb535963
|
Provenance
The following attestation bundles were made for dotenvage-0.6.2-cp310-abi3-win_amd64.whl:
Publisher:
ci.yml on dataroadinc/dotenvage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenvage-0.6.2-cp310-abi3-win_amd64.whl -
Subject digest:
95ab59c8cd49c8b0045cabda448511028c4cf36fabe2d92cfe357bab1b3c6547 - Sigstore transparency entry: 1418734368
- Sigstore integration time:
-
Permalink:
dataroadinc/dotenvage@6737145128c3e076e365427906844a0f8643a910 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dataroadinc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6737145128c3e076e365427906844a0f8643a910 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dotenvage-0.6.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: dotenvage-0.6.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 680.6 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08f7b7b3bdabdb323a5525ebd5758282cdf6ad28a902ba7e921a8b53d668b9b8
|
|
| MD5 |
274c688925493b8950ca7c01ad623d09
|
|
| BLAKE2b-256 |
78a3ce97e644ab63c97a43d028cd0d69e9119d0df1181cfb73df35d01e8e4a2b
|
Provenance
The following attestation bundles were made for dotenvage-0.6.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
ci.yml on dataroadinc/dotenvage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenvage-0.6.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
08f7b7b3bdabdb323a5525ebd5758282cdf6ad28a902ba7e921a8b53d668b9b8 - Sigstore transparency entry: 1418733799
- Sigstore integration time:
-
Permalink:
dataroadinc/dotenvage@6737145128c3e076e365427906844a0f8643a910 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dataroadinc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6737145128c3e076e365427906844a0f8643a910 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dotenvage-0.6.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: dotenvage-0.6.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 643.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
616cfbf1d92bd57a6589f0ffb9826ae90c702042cc7f3beff4b768590ac39f58
|
|
| MD5 |
a21c63c892e94471926f17a32561b465
|
|
| BLAKE2b-256 |
f9c2a36ff46c15e5c72e7c80f27c43092a340bc577da48d463e1aa525a3eb7a0
|
Provenance
The following attestation bundles were made for dotenvage-0.6.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
ci.yml on dataroadinc/dotenvage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenvage-0.6.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
616cfbf1d92bd57a6589f0ffb9826ae90c702042cc7f3beff4b768590ac39f58 - Sigstore transparency entry: 1418734047
- Sigstore integration time:
-
Permalink:
dataroadinc/dotenvage@6737145128c3e076e365427906844a0f8643a910 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dataroadinc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6737145128c3e076e365427906844a0f8643a910 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dotenvage-0.6.2-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: dotenvage-0.6.2-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 679.1 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd6b141e4d4e6d7bc2721ba91196b64ed2526d2589763d97d743fe1276739694
|
|
| MD5 |
45e3aff02ceae187bf3e7875402c4206
|
|
| BLAKE2b-256 |
1db57ed753c08cf497e6c71d77bf700bda2a7fbba25472a8f81d3bcba976effb
|
Provenance
The following attestation bundles were made for dotenvage-0.6.2-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
ci.yml on dataroadinc/dotenvage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenvage-0.6.2-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
fd6b141e4d4e6d7bc2721ba91196b64ed2526d2589763d97d743fe1276739694 - Sigstore transparency entry: 1418734591
- Sigstore integration time:
-
Permalink:
dataroadinc/dotenvage@6737145128c3e076e365427906844a0f8643a910 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dataroadinc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6737145128c3e076e365427906844a0f8643a910 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dotenvage-0.6.2-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: dotenvage-0.6.2-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 697.8 kB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0fdf861e99a547971385409f17f06858c18fb65032b33b05cf911a7bba17c70
|
|
| MD5 |
7af6061fb60b1505c990f6cca3051e7f
|
|
| BLAKE2b-256 |
e5abc8bd5cf804e5785e5e3ed94e95c763db7d52ac7f98aa889f9c1a88cbfe97
|
Provenance
The following attestation bundles were made for dotenvage-0.6.2-cp310-abi3-macosx_10_12_x86_64.whl:
Publisher:
ci.yml on dataroadinc/dotenvage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenvage-0.6.2-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
e0fdf861e99a547971385409f17f06858c18fb65032b33b05cf911a7bba17c70 - Sigstore transparency entry: 1418734249
- Sigstore integration time:
-
Permalink:
dataroadinc/dotenvage@6737145128c3e076e365427906844a0f8643a910 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dataroadinc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6737145128c3e076e365427906844a0f8643a910 -
Trigger Event:
push
-
Statement type: