Resolve env vars from secret stores.
Project description
envresolve
Resolve environment variables from secret stores like Azure Key Vault.
Features
- Variable expansion: Expand
${VAR}and$VARsyntax in strings - Secret resolution: Fetch secrets from Azure Key Vault (more providers coming)
- Circular reference detection: Prevents infinite loops in variable chains
- Type-safe: Full mypy type checking support
Quick Start
Variable Expansion
Expand variables without connecting to external services:
from envresolve import expand_variables
env = {"VAULT": "corp-kv", "SECRET": "db-password"}
result = expand_variables("akv://${VAULT}/${SECRET}", env)
print(result) # akv://corp-kv/db-password
Load from .env File
Load environment variables from a .env file with automatic secret resolution:
import envresolve
# .env file content:
# VAULT_NAME=my-vault
# DATABASE_URL=akv://${VAULT_NAME}/db-url
# API_KEY=akv://${VAULT_NAME}/api-key
# Requires: pip install envresolve[azure]
# Requires: Azure authentication (az login, Managed Identity, etc.)
envresolve.register_azure_kv_provider()
# Load .env and resolve all secret URIs
# By default, exports to os.environ
resolved_vars = envresolve.load_env(".env")
# Or load without exporting
resolved_vars = envresolve.load_env(".env", export=False)
Direct Secret Resolution
Fetch individual secrets from Azure Key Vault:
import envresolve
# Requires: pip install envresolve[azure]
# Requires: Azure authentication (az login, Managed Identity, etc.)
try:
envresolve.register_azure_kv_provider()
secret_value = envresolve.resolve_secret("akv://corp-vault/db-password")
print(secret_value)
except envresolve.ProviderRegistrationError as e:
print(f"Azure SDK not available: {e}")
except envresolve.SecretResolutionError as e:
print(f"Failed to fetch secret: {e}")
Resolve Existing Environment Variables
Resolve secret URIs already set in os.environ (useful for containerized applications):
import os
import envresolve
# Environment variables set by container orchestrator or parent process
os.environ["API_KEY"] = "akv://prod-vault/api-key"
os.environ["DB_PASSWORD"] = "akv://prod-vault/db-password"
# Requires: pip install envresolve[azure]
envresolve.register_azure_kv_provider()
# Resolve all environment variables containing secret URIs
resolved = envresolve.resolve_os_environ()
# Resolve only specific keys
resolved = envresolve.resolve_os_environ(keys=["API_KEY"])
# Resolve variables with prefix and strip the prefix
# DEV_API_KEY -> API_KEY, DEV_DB_URL -> DB_URL
os.environ["DEV_API_KEY"] = "akv://dev-vault/api-key"
os.environ["DEV_DB_URL"] = "akv://dev-vault/db-url"
resolved = envresolve.resolve_os_environ(prefix="DEV_")
Installation
# Basic installation (variable expansion only)
pip install envresolve
# With Azure Key Vault support
pip install envresolve[azure]
Documentation
Full documentation: https://osoekawaitlab.github.io/envresolve/
Development
Setup
This project uses uv for dependency management and nox for task automation:
# Install uv (if not already installed)
pip install uv
# Clone the repository
git clone https://github.com/osoekawaitlab/envresolve.git
cd envresolve
# Install dependencies (including dev dependencies)
uv pip install -e ".[azure]" --group=dev
Running Tests
# Quick test during development
nox -s tests_unit # Unit tests only (fast)
nox -s tests_e2e # E2E tests with mocked Azure SDK
# Full test suite
nox -s tests # All tests with coverage report (HTML in htmlcov/)
# Test across Python versions
nox -s tests_all_versions # Test on Python 3.10-3.14
# Test without Azure SDK
nox -s tests_without_azure # For environments without Azure dependencies
Code Quality
# Run all quality checks
nox -s quality # Type checking (mypy) + linting (ruff)
# Individual checks
nox -s mypy # Type checking only
nox -s lint # Linting only
nox -s format_code # Auto-format code
# Run everything
nox -s check_all # Tests + quality checks
Live Azure Tests
Optional integration tests against real Azure Key Vault:
# One-time setup
cd infra/terraform
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your Azure credentials
terraform init
terraform apply
# Before running tests
az login
source scripts/setup_live_tests.sh
# Run live tests
nox -s tests_live
See Live Azure Tests documentation for detailed setup instructions.
Build Documentation
# Build documentation
nox -s docs_build
# Serve documentation locally (with live reload)
nox -s docs_serve # Open http://localhost:8000
Contributing
See Contributing Guide for guidelines on:
- Code style and conventions
- Test-driven development workflow
- Creating issues and pull requests
- Architecture Decision Records (ADRs)
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 envresolve-0.1.3.tar.gz.
File metadata
- Download URL: envresolve-0.1.3.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f409d6f756a64a4175477671ff580eb0068423b655987ee01c0acf55b925e65
|
|
| MD5 |
c97f1b4c47d3e69da788cb5bff7db439
|
|
| BLAKE2b-256 |
4b116e0f89fdf1376cd485574de9b9cd991c619177e21ff0abc52edc68d8df2f
|
File details
Details for the file envresolve-0.1.3-py3-none-any.whl.
File metadata
- Download URL: envresolve-0.1.3-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a71657248a11d236c1ac5a90c91217c218fef11572497ec8659a26a3b04837a9
|
|
| MD5 |
f1e4b850c39bc3754e450d4b5013b65e
|
|
| BLAKE2b-256 |
2fe995daeaa9058edea38f19c4260697821eb72cd6107d434e99bcb5461aad42
|