Registry / azure / azure-keyvault-secrets

azure-keyvault-secrets

JSON →
library4.11.2pypypi✓ verified 25d ago

The Azure Key Vault Secrets client library for Python (version 4.10.0) provides secure storage and management for sensitive information like tokens, passwords, API keys, and certificates. As part of the actively developed Azure SDK for Python, it maintains a regular release cadence with updates typically occurring every few months to introduce new features and improvements.

pip install azure-keyvault-secrets azure-identity
INSTALL
IMPORT
SIG · AZURE-KEYVAULT-SEC
A
azure-keyvault-secrets
azurepythonv4.11.2
Install
3.7s avg
Import
444ms
Disk
43MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.11.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.470s · 43.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.7s · import 0.418s · 44MB
43MB installed
● package 43MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SecretClient
from azure.keyvault.secrets import SecretClient
The primary client for interacting with Azure Key Vault secrets.
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import DefaultAzureCredential
Authentication credentials are provided by the `azure-identity` library, not `azure-keyvault-secrets` directly. `DefaultAzureCredential` is recommended for most scenarios as it handles various authentication flows.
KeyVaultSecret
from azure.keyvault.secrets import KeyVaultSecret
Represents a secret retrieved from Azure Key Vault, including its value and attributes.
SecretProperties
from azure.keyvault.secrets import SecretProperties
Represents the attributes of a secret, such as its expiration date, content type, and tags.

This quickstart demonstrates how to authenticate with Azure Key Vault using `DefaultAzureCredential` and perform basic secret operations: setting a secret, retrieving it, and initiating its deletion. Ensure you have the `KEY_VAULT_URL` environment variable set to your Key Vault's URI (e.g., `https://<your-keyvault-name>.vault.azure.net`). Your identity must have appropriate permissions (e.g., 'Key Vault Secrets User' RBAC role or 'Get', 'Set', 'Delete' permissions via access policies) to perform these operations.

import os from azure.keyvault.secrets import SecretClient from azure.identity import DefaultAzureCredential # Retrieve the Key Vault URL from an environment variable key_vault_url = os.environ.get("KEY_VAULT_URL", "") if not key_vault_url: raise ValueError("KEY_VAULT_URL environment variable not set.") # Authenticate using DefaultAzureCredential, which handles various authentication flows credential = DefaultAzureCredential() # Create a SecretClient secret_client = SecretClient(vault_url=key_vault_url, credential=credential) secret_name = "MyTestSecret" secret_value = "mysecretvalue123" print(f"Setting a secret named '{secret_name}'...") # Set a secret set_secret = secret_client.set_secret(secret_name, secret_value) print(f"Secret set: {{set_secret.name}}, version: {{set_secret.id}}") print(f"Retrieving the secret named '{secret_name}'...") # Get a secret retrieved_secret = secret_client.get_secret(secret_name) print(f"Secret retrieved: {{retrieved_secret.name}}, value: {{retrieved_secret.value}}") print(f"Deleting the secret named '{secret_name}'...") # Delete a secret (soft-delete, if enabled on the vault) deleted_secret = secret_client.begin_delete_secret(secret_name).result() print(f"Secret deleted: {{deleted_secret.name}}, recovery ID: {{deleted_secret.recovery_id}}") print("Done.")
Debug
Known issues
breakingThe legacy `azure-keyvault` package has been split into specific client libraries: `azure-keyvault-keys`, `azure-keyvault-secrets`, and `azure-keyvault-certificates`. The `azure-keyvault` package no longer contains code and only installs these sub-packages. Direct imports from `azure.keyvault` will fail.
fix
Migrate your code to use the new scoped packages and their specific client classes (e.g., `from azure.keyvault.secrets import SecretClient`).
affects: <4.0.0
gotchaCommon errors (HTTP 403 Forbidden) are typically due to incorrect permissions. Azure Key Vault uses either Role-Based Access Control (RBAC) or legacy access policies. The authenticated identity (user, service principal, managed identity) must have explicit permissions (e.g., 'Key Vault Secrets User' role or 'Get', 'Set', 'Delete' access policy permissions) for the desired operations.
fix
Verify that the identity used for authentication has the necessary RBAC role assignments (recommended) or access policy entries configured on the Azure Key Vault. Ensure network firewall rules are not blocking access if the Key Vault has network restrictions.
affects: All versions
gotchaFrequent requests can lead to Key Vault throttling (HTTP 429 Too Many Requests). Key Vault is designed for secure storage, not as a high-throughput runtime database. Avoid fetching secrets on every application request.
fix
Implement caching mechanisms for secrets within your application. Use a singleton pattern for `SecretClient` instances and the credential object to reduce connection overhead and token refresh frequency.
affects: All versions
breakingStarting with Azure Key Vault REST API version 2026-02-01 (and corresponding SDKs), Azure RBAC becomes the *default* access control model for *newly created vaults*. While existing vaults retain their current model, deployment scripts creating new vaults might implicitly get RBAC as default, potentially causing `403 Forbidden` errors if RBAC roles are not assigned.
fix
Explicitly define the access control model (`enableRbacAuthorization`) when creating new vaults through infrastructure-as-code. Ensure that appropriate RBAC roles (e.g., 'Key Vault Secrets User') are assigned to identities that need to interact with new vaults. The deadline to migrate deployment scripts is February 27, 2027.
affects: Deployment scripts using API versions >= 2026-02-01 or future SDKs
breakingSupport for Python 2.7 has officially ended. This library requires Python 3.9 or later.
fix
Upgrade your Python environment to 3.9 or newer.
affects: <4.3.0
breakingThe Key Vault client requires the URL of the Azure Key Vault. This is typically provided via an environment variable (e.g., `KEY_VAULT_URL`) or passed directly to the client constructor, and is essential for initializing the client.
fix
Ensure the environment variable `KEY_VAULT_URL` (or the equivalent configuration parameter) is set with the URL of your Azure Key Vault, typically in the format `https://<your-key-vault-name>.vault.azure.net/`.
affects: All versions
breakingThe script requires the `KEY_VAULT_URL` environment variable to be set, typically to the URL of your Azure Key Vault instance. This variable is crucial for the `SecretClient` to know which Key Vault to connect to.
fix
Set the `KEY_VAULT_URL` environment variable to the appropriate Azure Key Vault URL before running the script. Example: `export KEY_VAULT_URL="https://YOUR_KEY_VAULT_NAME.vault.azure.net/"` or define it in your deployment environment.
affects: All versions
Upgrade
Version history
4.11.2latest on PyPI · released Aug 25, 2026
Audit
Dependencies
azure-identityrequiredRequired for Azure Active Directory authentication, which is the recommended method for interacting with Azure Key Vault.
azure-corerequiredCore dependency for all Azure SDKs, providing shared primitives.
isodaterequiredLikely used for parsing and formatting ISO 8601 date/time strings for Key Vault metadata.
typing-extensionsrequiredProvides backported and experimental type hints.
Agent activity
70 hits · last 30 days
node
60
Bingbot
1
Perplexity
1
OpenAI (training)
1
Resources
azure-keyvault-secrets — pip install azure-keyvault-secrets · libregistry