Azure API Management SDK for Python
使用 Python SDK 管理 Azure API
此技能帮助开发者使用 Python 集成和管理 Azure API 管理服务,实现自动化的 API 部署和管理流程。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“Azure API Management SDK for Python”。 创建 API Management 服务实例
预期结果:
```python
from azure.mgmt.apimanagement import ApiManagementClient
from azure.identity import DefaultAzureCredential
# Initialize the client
credential = DefaultAzureCredential()
subscription_id = "your-subscription-id"
resource_group_name = "your-resource-group"
service_name = "your-api-service"
client = ApiManagementClient(credential, subscription_id)
# Create the API Management service
poller = client.api_management_service.begin_create_or_update(
resource_group_name,
service_name,
{
'location': 'eastus',
'publisher_name': 'Your Company',
'publisher_email': 'admin@company.com',
'sku_name': 'Developer',
'sku_capacity': 1
}
)
result = poller.result()
print(f"API Management service created: {result.name}")
```
正在使用“Azure API Management SDK for Python”。 注册新 API
预期结果:
```python
# Register a new API in API Management
api_id = "my-new-api"
client.api.begin_create_or_update(
resource_group_name,
service_name,
api_id,
{
'display_name': 'My New API',
'path': 'myapi',
'service_url': 'https://api.example.com',
'protocols': ['https']
}
)
```
正在使用“Azure API Management SDK for Python”。 配置 API 策略
预期结果:
```python
# Apply rate limiting policy
client.api_policy.create_or_update(
resource_group_name,
service_name,
api_id,
{
'format': 'xml',
'value': '<policies><inbound><rate-limit-by-key calls="100" renewal-period="60" counter-key="@(context.Request.IpAddress)" /></inbound></policies>'
}
)
```
安全审计
安全This is a prompt-only skill containing documentation and guidance for the Azure API Management SDK for Python. The static analyzer scanned 0 files and detected 0 potential security issues. The skill provides educational content about Azure API Management without any executable code that could pose security risks.
质量评分
你能构建什么
自动化 API 部署的 DevOps 工程师
使用 Python 脚本在 CI/CD 流程中自动化创建和配置 API 管理实例。
构建 API 网关的后端开发者
使用 SDK 以编程方式创建 API、配置速率限制并为后端服务设置身份验证。
管理 API 基础设施的平台工程师
跨不同环境管理多个 API 管理实例、产品和订阅。
试试这些提示
展示如何使用 Python SDK 在 Azure API Management 中创建新 API。包括设置 API、添加操作和配置后端服务的代码。
如何使用 Python 在 Azure API Management 中为 API 配置 JWT 验证和 OAuth2 身份验证策略?
编写 Python 代码将 OpenAPI 3.0 规范导入 Azure API Management 并生成文档。
展示如何使用 Azure API Management Python SDK 配置速率限制策略和产品订阅配额。
最佳实践
- 使用托管标识进行身份验证,而不是在代码中存储凭据
- 按产品组织 API,并使用订阅密钥进行访问控制
- 从一开始就为 API 应用版本控制,以实现平滑更新
避免
- 不要在源代码中硬编码订阅密钥或机密
- 避免在未经测试的情况下直接在生产环境中配置策略
- 不要在没有 API 管理层的情况下直接暴露后端服务
常见问题
什么是 Azure API Management?
我需要 Azure 订阅才能使用此技能吗?
支持哪些 Python 版本?
此技能可以帮助进行 API 版本控制吗?
如何向 Azure 进行身份验证?
我可以导入现有的 OpenAPI 规范吗?
开发者详情
作者
sickn33许可证
MIT
仓库
https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/azure-mgmt-apimanagement-py引用
main
文件结构
📄 SKILL.md