azure-keyvault-py
Azure Key Vault SDK for Python. Use for secrets, keys, and certificates management with secure storage. Triggers: "key vault", "SecretClient", "KeyClient", "CertificateClient", "secrets", "encryption keys".
- License 许可
- MIT
- 所属仓库
- microsoft/skills
- 最近更新
- 2026-11-11
- Stars
- ★ 3.2k
- Forks
- 364
01 前言 Front Matter
- name
- azure-keyvault-py
- license
- MIT
- metadata
- { "author": "Microsoft", "package": "azure-keyvault-secrets, azure-keyvault-keys, azure-keyvault-certificates", "version": "1.0.0" }
- description
- Azure Key Vault SDK for Python. Use for secrets, keys, and certificates management with secure storage. Triggers: "key vault", "SecretClient", "KeyClient", "CertificateClient", "secrets", "encryption keys".
02 资源文件 126
- 参考文档copilot-studio/agent.sync.yaml174 B
- 参考文档copilot-studio/behaviors/aibast_at-risk-client-prioritization.mcs.yml574 B
- 参考文档copilot-studio/behaviors/aibast_client-engagement-analysis.mcs.yml2.0 KB
- 参考文档copilot-studio/behaviors/aibast_client-portfolio-health-dashboard.mcs.yml616 B
- 参考文档copilot-studio/behaviors/aibast_client-retention-playbook.mcs.yml1.9 KB
- 参考文档copilot-studio/behaviors/aibast_client-satisfaction-trend.mcs.yml530 B
- 参考文档copilot-studio/behaviors/aibast_qbr-summary.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_risk-analysis.mcs.yml1.1 KB
- 参考文档copilot-studio/behaviors/aibast_stakeholder-outreach.mcs.yml1.2 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_client-health-retention-playbook.md15.0 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_client-health-retention-playbook.md.mcs.yml188 B
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_client-health-synthetic-portfolio.md12.3 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_client-health-synthetic-portfolio.md.mcs.yml190 B
- 参考文档copilot-studio/settings.mcs.yml9.0 KB
- 参考文档deployment.json3.2 KB
- 参考文档EASY-MODE-COPILOT-CHAT.md229 B
- 参考文档EASY-MODE-PERSONLESS.md229 B
- 参考文档EASY-MODE.md2.7 KB
- 参考文档evals/copilot-studio-preview-evidence.json2.6 KB
- 参考文档evals/dataverse-draft-evidence.json1.6 KB
- 参考文档evals/manual-build-evidence.json4.6 KB
- 参考文档evals/onepager-map.json2.3 KB
- 参考文档evals/transcripts.json29.5 KB
- 参考文档evals/visual-checkpoints.json36.6 KB
- 参考文档evidence-report.html33.2 KB
- 参考文档export-manifest.json62.1 KB
- 资产文件exports/client-health-score-copilot-studio-solution.zip26.3 KB
- 参考文档exports/client-health-score-deployment-settings.json206 B
- 参考文档exports/client-health-score-solution-export.json1.1 KB
- 参考文档exports/README.md1.5 KB
- 参考文档field-guide.html38.6 KB
- 参考文档FIELD-GUIDE.md14.2 KB
- 参考文档FLOW.md1.3 KB
- 参考文档manual-tutorial.html106.0 KB
- 参考文档manual/GLOBAL-INSTRUCTIONS.md7.2 KB
- 参考文档manual/knowledge/aibast_client-health-retention-playbook.md15.0 KB
- 参考文档manual/knowledge/aibast_client-health-synthetic-portfolio.md12.3 KB
- 参考文档quest.html163.6 KB
- 参考文档README.md2.9 KB
- 参考文档references/capabilities.md1.3 KB
- 参考文档references/non-hero-scenarios.md1.0 KB
- 资产文件screenshots/assisted/01-review-build.jpg99.2 KB
- 资产文件screenshots/assisted/02-chs-01.jpg202.1 KB
- 资产文件screenshots/assisted/03-chs-02.jpg132.3 KB
- 资产文件screenshots/assisted/04-chs-03.jpg162.6 KB
- 资产文件screenshots/assisted/05-chs-04.jpg260.4 KB
- 资产文件screenshots/assisted/06-chs-05.jpg318.9 KB
- 资产文件screenshots/assisted/07-chs-06.jpg158.0 KB
- 资产文件screenshots/assisted/08-chs-07.jpg137.4 KB
- 资产文件screenshots/assisted/09-chs-08.jpg231.3 KB
- 资产文件screenshots/assisted/10-confirm-draft.jpg27.9 KB
- 资产文件screenshots/assisted/annotated/01-review-build.png108.9 KB
- 资产文件screenshots/assisted/annotated/02-chs-01.png196.7 KB
- 资产文件screenshots/assisted/annotated/03-chs-02.png132.8 KB
- 资产文件screenshots/assisted/annotated/04-chs-03.png160.9 KB
- 资产文件screenshots/assisted/annotated/05-chs-04.png252.5 KB
- 资产文件screenshots/assisted/annotated/06-chs-05.png313.6 KB
- 资产文件screenshots/assisted/annotated/07-chs-06.png152.7 KB
- 资产文件screenshots/assisted/annotated/08-chs-07.png138.7 KB
- 资产文件screenshots/assisted/annotated/09-chs-08.png231.6 KB
- 资产文件screenshots/assisted/annotated/10-confirm-draft.png28.0 KB
- 参考文档screenshots/assisted/browserfilm.json1.9 KB
- 资产文件screenshots/assisted/copilot-assisted-contact-sheet.jpg244.5 KB
- 资产文件screenshots/assisted/copilot-assisted-walkthrough.gif1.4 MB
- 参考文档screenshots/assisted/README.md468 B
- 资产文件screenshots/manual/01-create-blank-agent.jpg57.7 KB
- 资产文件screenshots/manual/02-name-agent.jpg59.4 KB
- 资产文件screenshots/manual/03-enter-instructions.jpg131.8 KB
- 资产文件screenshots/manual/04-save-instructions.jpg131.7 KB
- 资产文件screenshots/manual/05-remove-web-search.jpg131.9 KB
- 资产文件screenshots/manual/06-add-aibast-client-health-retention-playbook.jpg133.5 KB
- 资产文件screenshots/manual/07-add-aibast-client-health-synthetic-portfolio.jpg136.3 KB
- 资产文件screenshots/manual/08-add-aibast-at-risk-clients-04.jpg139.7 KB
- 资产文件screenshots/manual/09-add-aibast-engagement-analysis-02.jpg141.9 KB
- 资产文件screenshots/manual/10-add-aibast-health-dashboard-01.jpg144.3 KB
- 资产文件screenshots/manual/11-add-aibast-qbr-summary-08.jpg145.7 KB
- 资产文件screenshots/manual/12-add-aibast-retention-plan-05.jpg147.7 KB
- 资产文件screenshots/manual/13-add-aibast-risk-analysis-06.jpg147.1 KB
- 资产文件screenshots/manual/14-add-aibast-satisfaction-trend-03.jpg146.9 KB
- 资产文件screenshots/manual/15-add-aibast-stakeholder-outreach-07.jpg146.2 KB
- 资产文件screenshots/manual/16-review-inventory.jpg146.2 KB
- 资产文件screenshots/manual/17-review-skills.jpg136.6 KB
- 资产文件screenshots/manual/18-review-skills-more.jpg139.1 KB
- 资产文件screenshots/manual/19-open-preview.jpg32.2 KB
- 资产文件screenshots/manual/20-chs-01.jpg231.2 KB
- 资产文件screenshots/manual/21-chs-02.jpg86.4 KB
- 资产文件screenshots/manual/22-chs-03.jpg171.6 KB
- 资产文件screenshots/manual/23-chs-04.jpg189.6 KB
- 资产文件screenshots/manual/24-chs-05.jpg125.0 KB
- 资产文件screenshots/manual/25-chs-06.jpg165.3 KB
- 资产文件screenshots/manual/26-chs-07.jpg163.8 KB
- 资产文件screenshots/manual/27-chs-08.jpg116.0 KB
- 资产文件screenshots/manual/28-confirm-draft.jpg28.7 KB
- 资产文件screenshots/manual/annotated/01-create-blank-agent.png62.7 KB
- 资产文件screenshots/manual/annotated/02-name-agent.png63.8 KB
- 资产文件screenshots/manual/annotated/03-enter-instructions.png130.5 KB
- 资产文件screenshots/manual/annotated/04-save-instructions.png125.0 KB
- 资产文件screenshots/manual/annotated/05-remove-web-search.png131.2 KB
- 资产文件screenshots/manual/annotated/06-add-aibast-client-health-retention-playbook.png133.0 KB
- 资产文件screenshots/manual/annotated/07-add-aibast-client-health-synthetic-portfolio.png135.3 KB
- 资产文件screenshots/manual/annotated/08-add-aibast-at-risk-clients-04.png137.4 KB
- 资产文件screenshots/manual/annotated/09-add-aibast-engagement-analysis-02.png139.2 KB
- 资产文件screenshots/manual/annotated/10-add-aibast-health-dashboard-01.png141.0 KB
- 资产文件screenshots/manual/annotated/11-add-aibast-qbr-summary-08.png141.6 KB
- 资产文件screenshots/manual/annotated/12-add-aibast-retention-plan-05.png143.6 KB
- 资产文件screenshots/manual/annotated/13-add-aibast-risk-analysis-06.png143.1 KB
- 资产文件screenshots/manual/annotated/14-add-aibast-satisfaction-trend-03.png143.4 KB
- 资产文件screenshots/manual/annotated/15-add-aibast-stakeholder-outreach-07.png142.7 KB
- 资产文件screenshots/manual/annotated/16-review-inventory.png146.4 KB
- 资产文件screenshots/manual/annotated/17-review-skills.png146.7 KB
- 资产文件screenshots/manual/annotated/18-review-skills-more.png153.7 KB
- 资产文件screenshots/manual/annotated/19-open-preview.png32.0 KB
- 资产文件screenshots/manual/annotated/20-chs-01.png233.3 KB
- 资产文件screenshots/manual/annotated/21-chs-02.png95.2 KB
- 资产文件screenshots/manual/annotated/22-chs-03.png177.5 KB
- 资产文件screenshots/manual/annotated/23-chs-04.png201.7 KB
- 资产文件screenshots/manual/annotated/24-chs-05.png134.7 KB
- 资产文件screenshots/manual/annotated/25-chs-06.png163.5 KB
- 资产文件screenshots/manual/annotated/26-chs-07.png168.3 KB
- 资产文件screenshots/manual/annotated/27-chs-08.png124.2 KB
- 资产文件screenshots/manual/annotated/28-confirm-draft.png29.3 KB
- 参考文档screenshots/manual/browserfilm.json4.8 KB
- 资产文件screenshots/manual/manual-build-contact-sheet.jpg984.0 KB
- 资产文件screenshots/manual/manual-build-walkthrough.gif6.4 MB
- 参考文档screenshots/manual/README.md461 B
- 参考文档screenshots/README.md522 B
03 SKILL.md 正文
Azure Key Vault SDK for Python
Secure storage and management for secrets, cryptographic keys, and certificates.
Installation
# Secrets
pip install azure-keyvault-secrets azure-identity
# Keys (cryptographic operations)
pip install azure-keyvault-keys azure-identity
# Certificates
pip install azure-keyvault-certificates azure-identity
# All
pip install azure-keyvault-secrets azure-keyvault-keys azure-keyvault-certificates azure-identity
Environment Variables
AZURE_KEYVAULT_URL=https://<vault-name>.vault.azure.net/ # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
Authentication & Lifecycle
? Two rules apply to every code sample below:
- Prefer
DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
- Local dev:
DefaultAzureCredentialworks as-is.- Production: set
AZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.- Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
- Sync:
with <Client>(...) as client:- Async:
async with <Client>(...) as client:andasync with DefaultAzureCredential() as credential:(fromazure.identity.aio)Snippets may abbreviate this setup, but production code should always follow both rules.
Secrets
SecretClient Setup
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.keyvault.secrets import SecretClient
# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()
vault_url = "https://<vault-name>.vault.azure.net/"
with SecretClient(vault_url=vault_url, credential=credential) as client:
# All secret operations go inside this block (see examples below)
...
Secret Operations
# Set secret
secret = client.set_secret("database-password", "super-secret-value")
print(f"Created: {secret.name}, version: {secret.properties.version}")
# Get secret
secret = client.get_secret("database-password")
print(f"Value: {secret.value}")
# Get specific version
secret = client.get_secret("database-password", version="abc123")
# List secrets (names only, not values)
for secret_properties in client.list_properties_of_secrets():
print(f"Secret: {secret_properties.name}")
# List versions
for version in client.list_properties_of_secret_versions("database-password"):
print(f"Version: {version.version}, Created: {version.created_on}")
# Delete secret (soft delete)
poller = client.begin_delete_secret("database-password")
deleted_secret = poller.result()
# Purge (permanent delete, if soft-delete enabled)
client.purge_deleted_secret("database-password")
# Recover deleted secret
client.begin_recover_deleted_secret("database-password").result()
Keys
KeyClient Setup
from azure.identity import DefaultAzureCredential
from azure.keyvault.keys import KeyClient
credential = DefaultAzureCredential()
vault_url = "https://<vault-name>.vault.azure.net/"
with KeyClient(vault_url=vault_url, credential=credential) as client:
# All key operations go inside this block (see examples below)
...
Key Operations
from azure.keyvault.keys import KeyType
# Create RSA key
rsa_key = client.create_rsa_key("rsa-key", size=2048)
# Create EC key
ec_key = client.create_ec_key("ec-key", curve="P-256")
# Get key
key = client.get_key("rsa-key")
print(f"Key type: {key.key_type}")
# List keys
for key_properties in client.list_properties_of_keys():
print(f"Key: {key_properties.name}")
# Delete key
poller = client.begin_delete_key("rsa-key")
deleted_key = poller.result()
Cryptographic Operations
from azure.keyvault.keys.crypto import CryptographyClient, EncryptionAlgorithm
# Get crypto client for a specific key
# crypto_client = CryptographyClient(key, credential=credential)
# Or from key ID
with CryptographyClient(
"https://<vault>.vault.azure.net/keys/<key-name>/<version>",
credential=credential
) as crypto_client:
# Encrypt
plaintext = b"Hello, Key Vault!"
result = crypto_client.encrypt(EncryptionAlgorithm.rsa_oaep, plaintext)
ciphertext = result.ciphertext
# Decrypt
result = crypto_client.decrypt(EncryptionAlgorithm.rsa_oaep, ciphertext)
decrypted = result.plaintext
# Sign
from azure.keyvault.keys.crypto import SignatureAlgorithm
import hashlib
digest = hashlib.sha256(b"data to sign").digest()
result = crypto_client.sign(SignatureAlgorithm.rs256, digest)
signature = result.signature
# Verify
result = crypto_client.verify(SignatureAlgorithm.rs256, digest, signature)
print(f"Valid: {result.is_valid}")
Certificates
CertificateClient Setup
from azure.identity import DefaultAzureCredential
from azure.keyvault.certificates import CertificateClient, CertificatePolicy
credential = DefaultAzureCredential()
vault_url = "https://<vault-name>.vault.azure.net/"
with CertificateClient(vault_url=vault_url, credential=credential) as client:
# All certificate operations go inside this block (see examples below)
...
Certificate Operations
# Create self-signed certificate
policy = CertificatePolicy.get_default()
poller = client.begin_create_certificate("my-cert", policy=policy)
certificate = poller.result()
# Get certificate
certificate = client.get_certificate("my-cert")
print(f"Thumbprint: {certificate.properties.x509_thumbprint.hex()}")
# Get certificate with private key (as secret)
from azure.keyvault.secrets import SecretClient
with SecretClient(vault_url=vault_url, credential=credential) as secret_client:
cert_secret = secret_client.get_secret("my-cert")
# cert_secret.value contains PEM or PKCS12
# List certificates
for cert in client.list_properties_of_certificates():
print(f"Certificate: {cert.name}")
# Delete certificate
poller = client.begin_delete_certificate("my-cert")
deleted = poller.result()
Client Types Table
| Client | Package | Purpose |
|---|---|---|
SecretClient |
azure-keyvault-secrets |
Store/retrieve secrets |
KeyClient |
azure-keyvault-keys |
Manage cryptographic keys |
CryptographyClient |
azure-keyvault-keys |
Encrypt/decrypt/sign/verify |
CertificateClient |
azure-keyvault-certificates |
Manage certificates |
Async Clients
from azure.identity.aio import DefaultAzureCredential
from azure.keyvault.secrets.aio import SecretClient
async def get_secret():
async with DefaultAzureCredential() as credential:
async with SecretClient(vault_url=vault_url, credential=credential) as client:
secret = await client.get_secret("my-secret")
print(secret.value)
import asyncio
asyncio.run(get_secret())
Error Handling
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError
try:
secret = client.get_secret("nonexistent")
except ResourceNotFoundError:
print("Secret not found")
except HttpResponseError as e:
if e.status_code == 403:
print("Access denied - check RBAC permissions")
raise
Best Practices
- Pick sync OR async and stay consistent. Do not mix
azure.xxxsync clients withazure.xxx.aioasync clients in the same call path. Choose one mode per module. - Always use context managers for clients and async credentials. Wrap every client in
with Client(...) as client:(sync) orasync with Client(...) as client:(async). For asyncDefaultAzureCredentialfromazure.identity.aio, also useasync with credential:so tokens and transports are cleaned up. - Use
DefaultAzureCredentialfor code that runs locally. Use a specific token credential for code that runs in Azure. - Use managed identity in Azure-hosted applications
- Enable soft-delete for recovery (enabled by default)
- Use RBAC over access policies for fine-grained control
- Rotate secrets regularly using versioning
- Use Key Vault references in App Service/Functions config
- Cache secrets appropriately to reduce API calls
- Use async clients for high-throughput scenarios
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| references/non-hero-scenarios.md | Dedicated non-hero examples for secondary/advanced scenarios. |
04 同仓库更多 Skills
skill-creator
Guide for creating effective skills for AI coding agents working with Azure SDKs and Microsoft Foundry services. Use when creating new skills or updating existing skills.
podcast-generation
Generate AI-powered podcast-style audio narratives using Azure OpenAI's GPT Realtime Mini model via WebSocket. Use when building text-to-speech features, audio narrative generation, podcast creation from content, or integrating with Azure OpenAI Realtime API for real audio output. Covers full-stack implementation from React frontend to Python FastAPI backend with WebSocket streaming.
microsoft-docs
Understand Microsoft technologies by querying official documentation. Use whenever the user asks how something works, wants tutorials, needs configuration options, limits, quotas, or best practices for any Microsoft technology (Azure, .NET, M365, Windows, Power Platform, etc.)—even if they don't mention "docs." If the question is about understanding a concept rather than writing code, this is the right skill.
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP), Node/TypeScript (MCP SDK), or C#/.NET (Microsoft MCP SDK).
kql
KQL language expertise for writing correct, efficient Kusto Query Language queries. Covers syntax gotchas, join patterns, dynamic types, datetime pitfalls, regex patterns, serialization, memory management, result-size discipline, and advanced functions (geo, vector, graph). USE THIS SKILL whenever writing, debugging, or reviewing KQL queries — even simple ones — because the gotchas section prevents the most common errors that waste tool calls and cause expensive retry cascades. Trigger on: KQL, Kusto, ADX, Azure Data Explorer, Fabric Real-Time Intelligence, EventHouse, Log Analytics, log analysis, data exploration, time series, anomaly detection, summarize, where clause, join, extend, project, let statement, parse operator, extract function, any mention of pipe-forward query syntax.
github-issue-creator
Convert raw notes, error logs, voice dictation, or screenshots into crisp GitHub-flavored markdown issue reports. Use when the user pastes bug info, error messages, or informal descriptions and wants a structured GitHub issue. Supports images/GIFs for visual evidence.