Skip to main content

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. .env is read for markers; the rest is left to your own reader. Pass export_all=True and 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=False if 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.
  • Locallyaz login, with that role on your own account.
  • ElsewhereAZURE_TENANT_ID / AZURE_CLIENT_ID / AZURE_CLIENT_SECRET. These are read out of .env and exported for the SDK, which cannot see .env on 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

vaultref-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vaultref-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

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

Hashes for vaultref-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c7a49ad67e2194bee8879b16913277ca34c73f1137a860d2a137e957e8a9e7e6
MD5 a8119317a18a4d1c222860b1175451bb
BLAKE2b-256 ab43c5bf1f5d0ba848e0a4b67a0c3d9e751cf3ab73ff3bd647df5f1d386c9825

See more details on using hashes here.

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

Hashes for vaultref-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0442cd25c0d3b5faa50f168ae8f0ec8fe18853b379fb23f1edc2621846863140
MD5 d6f28450b4749b6acedbf7c55889660f
BLAKE2b-256 ae9284e8fbc01d24a0d523d3baf7741edeb72206171094ed9f5971bc6711aa39

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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