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.
Metadata
Release files for azure-keyvault-helper 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| azure_keyvault_helper-0.1.0.tar.gz | 5.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| azure_keyvault_helper-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / azure_keyvault_helper-0.1.0.tar.gz
| Download URL | azure_keyvault_helper-0.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0619f5e90a0a3b5f6b36dd7230ea6f102728cddca5d050aa1c0db1deb9e76c4b
|
|
BLAKE2b-256 checksum How to use checksums |
08646b5f53d03d6284cc6d0b7305d74d1df6af56f093c8c70b8bba388b7cdf4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / azure_keyvault_helper-0.1.0-py3-none-any.whl
| Download URL | azure_keyvault_helper-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0da760c425510608fce3de51738c119ba74dc5719206bfaac799741f0f39c12e
|
|
BLAKE2b-256 checksum How to use checksums |
6151de1fabdd07e5c64075af509b1b816ddff979273a7e72aa9bf0d8ebf6cc09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Security for azure-keyvault-helper 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.