A helper library for retrieving secrets from Azure Key Vault
Project description
Azure Key Vault Helper
A Python helper library for easily retrieving secrets from Azure Key Vault with support for development and production environments.
Features
- Simple interface for retrieving secrets from Azure Key Vault
- Automatic authentication using Azure Default Credentials
- Environment-aware: different behavior for development and production
- Fallback to environment variables when needed
- Batch secret retrieval support
Installation
pip install azure-keyvault-helper
Prerequisites
For Local Development
- Azure CLI installed and logged in (
az login) - Or set environment variables:
AZURE_CLIENT_IDAZURE_TENANT_IDAZURE_CLIENT_SECRET(if using service principal)
For Production
- Managed Identity enabled (when running in Azure)
- Or Service Principal configured with appropriate environment variables
Configuration
Set the following environment variables:
KEYVAULT_URL: The URL of your Azure Key Vault (e.g.,https://myvault.vault.azure.net/)ENVIRONMENT: Set todevelopmentorproduction(defaults toproduction)
Usage
Basic Usage
from azure_keyvault_helper import AzureKeyVaultHelper
# Initialize the helper
helper = AzureKeyVaultHelper()
# Get a single secret
secret_value = helper.get_secret("my-secret-name")
print(secret_value)
Using Global Helper
from azure_keyvault_helper import get_secret
# Automatically uses Key Vault or environment variables based on ENVIRONMENT
api_key = get_secret("api-key", fallback_env_var="API_KEY")
Batch Retrieval
from azure_keyvault_helper import AzureKeyVaultHelper
helper = AzureKeyVaultHelper()
secrets = helper.get_secrets_batch(["secret1", "secret2", "secret3"])
print(secrets)
Environment-Aware Usage
The library behaves differently based on the ENVIRONMENT variable:
Development Mode (ENVIRONMENT=development):
- Prefers environment variables over Key Vault
- Useful for local development without Key Vault access
Production Mode (ENVIRONMENT=production or unset):
- Uses Azure Key Vault primarily
- Falls back to environment variables if Key Vault is unavailable
import os
os.environ["ENVIRONMENT"] = "development"
from azure_keyvault_helper import get_secret
# In development: uses API_KEY env var if available
# In production: uses Key Vault secret "api-key", falls back to API_KEY env var
api_key = get_secret("api-key", fallback_env_var="API_KEY")
Authentication
The library uses DefaultAzureCredential which tries multiple authentication methods in order:
- Environment variables (for service principal)
- Managed Identity (when running in Azure)
- Azure CLI (when running locally and logged in)
- Visual Studio Code (if using VS Code Azure extension)
- Azure PowerShell (if authenticated)
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 azure_keyvault_helper-0.1.0.tar.gz.
File metadata
- Download URL: azure_keyvault_helper-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0619f5e90a0a3b5f6b36dd7230ea6f102728cddca5d050aa1c0db1deb9e76c4b
|
|
| MD5 |
b5d3ff5536f13d8b9aa385026007b939
|
|
| BLAKE2b-256 |
08646b5f53d03d6284cc6d0b7305d74d1df6af56f093c8c70b8bba388b7cdf4f
|
File details
Details for the file azure_keyvault_helper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: azure_keyvault_helper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0da760c425510608fce3de51738c119ba74dc5719206bfaac799741f0f39c12e
|
|
| MD5 |
aba78edbe1c24852019d2e4271681bb0
|
|
| BLAKE2b-256 |
6151de1fabdd07e5c64075af509b1b816ddff979273a7e72aa9bf0d8ebf6cc09
|