Skip to main content

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_ID
    • AZURE_TENANT_ID
    • AZURE_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 to development or production (defaults to production)

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:

  1. Environment variables (for service principal)
  2. Managed Identity (when running in Azure)
  3. Azure CLI (when running locally and logged in)
  4. Visual Studio Code (if using VS Code Azure extension)
  5. Azure PowerShell (if authenticated)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure_keyvault_helper-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

azure_keyvault_helper-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

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

Hashes for azure_keyvault_helper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0619f5e90a0a3b5f6b36dd7230ea6f102728cddca5d050aa1c0db1deb9e76c4b
MD5 b5d3ff5536f13d8b9aa385026007b939
BLAKE2b-256 08646b5f53d03d6284cc6d0b7305d74d1df6af56f093c8c70b8bba388b7cdf4f

See more details on using hashes here.

File details

Details for the file azure_keyvault_helper-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for azure_keyvault_helper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0da760c425510608fce3de51738c119ba74dc5719206bfaac799741f0f39c12e
MD5 aba78edbe1c24852019d2e4271681bb0
BLAKE2b-256 6151de1fabdd07e5c64075af509b1b816ddff979273a7e72aa9bf0d8ebf6cc09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page