vaultref
Environment variables that refers a secret in a vault instead of holding one.
# .env — checked in, readable at a glance
APP_ENV=production
APP_MONGO_URL=AZKV_MONGODB-HOST ← the vault holds the value
APP_SECRET_KEY=AZKV_APP-SIGNING-KEY
APP_PORT=8000
AZURE_KEY_VAULT_NAME=myvault
import vaultref
vaultref.load() # before anything reads config
Every value beginning with a registered marker is replaced by the secret it
names, written into os.environ, and read from there by whatever you already
use — pydantic-settings, Django settings, os.environ[...]. Nothing
downstream needs to know a vault exists.
Install
pip install vaultref[azure]
Where to call it
| Project | Put vaultref.load() … |
|---|---|
| pydantic-settings | above the first Settings() construction |
| Django | at the top of settings.py, before env() / os.environ reads |
| Flask | before app.config.from_prefixed_env() |
| Plain script / worker | first lines of main, before importing config |
It is idempotent and cached — calling it twice costs nothing.
Behaviour
- Only markers are exported.
.envis read for markers; the rest is left to your own reader. Passexport_all=Trueand it replaces python-dotenv entirely, resolving markers on the way through. - Real environment variables win over
.env, marker or not — matching pydantic-settings and django-environ, so a shell override still overrides. - A marker that will not resolve is fatal. Starting on the built-in
default means a localhost database or a freshly minted signing key: silent,
total, discovered later.
strict=Falseif you need a warning instead. - One round trip per secret, cached for the life of the process. A rotated secret reaches the app on its next restart.
- No marker anywhere ⇒ no vault contacted, no client built, no credentials needed. Local development with plain values needs nothing installed.
Azure Key Vault (AZKV_)
Vault from AZURE_KEY_VAULT_NAME (or AZURE_KEY_VAULT_URL for sovereign
clouds). Authentication is DefaultAzureCredential:
- On Azure — a managed identity with the Key Vault Secrets User role. Nothing in the environment.
- Locally —
az login, with that role on your own account. - Elsewhere —
AZURE_TENANT_ID/AZURE_CLIENT_ID/AZURE_CLIENT_SECRET. These are read out of.envand exported for the SDK, which cannot see.envon its own.
Secrets only. A Key Vault key has no readable value by design — it signs and wraps inside the vault and never leaves it.
Another backend
Three lines, and it works everywhere the Azure one does:
@vaultref.resolver("AWSSM_")
def aws_secrets_manager(name, env):
return boto3.client("secretsmanager").get_secret_value(
SecretId=name)["SecretString"]
APP_MONGO_URL=AWSSM_prod/mongo/url
Markers coexist — one project can read from two vaults during a migration.
Tests
python -m unittest discover -s tests # 11 tests, no vault needed
AZURE_KEY_VAULT_NAME=myvault VAULTREF_TEST_SECRET=MY-SECRET python tests/live.py # against a real vault
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 vaultref-0.1.0.tar.gz.
File metadata
- Download URL: vaultref-0.1.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7a49ad67e2194bee8879b16913277ca34c73f1137a860d2a137e957e8a9e7e6
|
|
| MD5 |
a8119317a18a4d1c222860b1175451bb
|
|
| BLAKE2b-256 |
ab43c5bf1f5d0ba848e0a4b67a0c3d9e751cf3ab73ff3bd647df5f1d386c9825
|
File details
Details for the file vaultref-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vaultref-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0442cd25c0d3b5faa50f168ae8f0ec8fe18853b379fb23f1edc2621846863140
|
|
| MD5 |
d6f28450b4749b6acedbf7c55889660f
|
|
| BLAKE2b-256 |
ae9284e8fbc01d24a0d523d3baf7741edeb72206171094ed9f5971bc6711aa39
|