Azure API Center Management SDK for Python
使用 Python SDK 管理 Azure API Center
Azure API Center 提供了一个中央存储库,用于发现和管理组织内的 API。此技能使 AI 助手能够使用官方 Python SDK 与 Azure API Center 进行交互,让开发人员可以自动化 API 清单管理、治理和生命周期操作。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“Azure API Center Management SDK for Python”。 如何在 Azure API Center 中创建新 API?
预期结果:
要使用 Python SDK 在 Azure API Center 中创建新 API:
1. 首先使用 DefaultAzureCredential 或 ServicePrincipalCredential 进行身份验证
2. 初始化 ApiCenterClient
3. 使用 apis.create_or_update() 方法
示例:
```python
from azure.identity import DefaultAzureCredential
from azure.mgmt.apicenter import ApiCenterClient
credential = DefaultAzureCredential()
client = ApiCenterClient(credential, subscription_id)
client.apis.create_or_update(
resource_group_name='my-rg',
service_name='my-api-center',
workspace_name='default',
api_name='my-new-api',
api={'properties': {'title': 'My API', 'description': 'API description'}}
)
```
正在使用“Azure API Center Management SDK for Python”。 管理 API 需要哪些权限?
预期结果:
要在 Azure API Center 中管理 API,您需要在相应范围内具有以下角色之一:
- API Center API Manager:完全管理访问权限
- API Center Service Contributor:创建和更新 API
- API Center Reader:只读访问权限
- 具有 Microsoft.ApiCenter/*/permissions 的自定义角色
服务主体或用户身份还必须能够访问包含 API Center 的 Azure 订阅。
安全审计
安全This is a prompt-only skill providing documentation and guidance for using the Azure API Center Management SDK for Python. Static analysis scanned 0 files (0 lines) and detected 0 potential security issues. The skill contains no executable code, scripts, network calls, filesystem access, or external command invocations. Risk score is 0/100. This is a safe, documentation-focused skill for AI assistants to help users interact with Azure API Center.
质量评分
你能构建什么
生成 SDK 初始化代码
创建 Python 代码以进行身份验证并为特定订阅和资源组初始化 Azure API Center 客户端。
自动化 API 清单操作
生成脚本以批量创建、更新或迁移多个工作区或环境中的 API 定义。
记录 API 治理策略
创建文档和代码示例,用于实施 API 标准、版本控制策略和生命周期管理工作流程。
试试这些提示
展示如何使用 Python SDK 和服务主体凭据进行身份验证并为 Azure API Center 创建客户端。
编写 Python 代码以列出特定工作区中注册的所有 API,包括其版本和规范。
生成代码以向 Azure API Center 中的现有 API 添加带有 OpenAPI 3.0 规范的新 API 版本。
展示如何使用 Azure API Center SDK 在不同环境中创建和管理 API 部署。
最佳实践
- 在生产环境中使用托管标识或服务主体进行身份验证,而不是将凭据存储在代码中
- 在调用 Azure SDK 方法时实施带有指数退避的重试策略,以处理暂时性故障
- 按工作区组织 API,以分离开发、暂存和生产 API 目录
避免
- 在源代码或配置文件中硬编码 Azure 凭据 - 改用环境变量或 Azure Key Vault
- 忽略 API 版本控制 - 始终创建新版本而不是覆盖现有版本以保持兼容性
- 向 SDK 客户端授予过于宽泛的权限 - 遵循 RBAC 角色的最小权限原则