azure-mgmt-apicenter-py について
azure-mgmt-apicenter-py は、Azure API Center の API カタログ、定義、デプロイ、ガバナンスを管理する Python SDK です。API カタログ管理を自動化する開発者や運用担当者向けです。
主な機能
- 01API Center サービスの作成と管理
- 02ワークスペースによる API 整理
- 03API とバージョンの登録
- 04API 仕様のインポート
- 05環境とデプロイの追跡
- 06メタデータスキーマの定義
活用シーン
- 01ワークスペース別の API カタログ管理
- 02分析用 API 仕様のインポート
- 03API のデプロイ先の追跡
- 04API メタデータの一貫した適用
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ sickn33/ agentic-awesome-skills --skill azure-mgmt-apicenter-pyインストール後、Claude Code で/azure-mgmt-apicenter-pyを入力して読み込まれたか確認します。
詳細
Azure API Center 管理 SDK for Python
Azure API Center で API インベントリ、メタデータ、ガバナンスを管理します。
インストール
pip install azure-mgmt-apicenter
pip install azure-identity
環境変数
AZURE_SUBSCRIPTION_ID=your-subscription-id
認証
from azure.identity import DefaultAzureCredential
from azure.mgmt.apicenter import ApiCenterMgmtClient
import os
client = ApiCenterMgmtClient(
credential=DefaultAzureCredential(),
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]
)
API Center の作成
from azure.mgmt.apicenter.models import Service
api_center = client.services.create_or_update(
resource_group_name="my-resource-group",
service_name="my-api-center",
resource=Service(
location="eastus",
tags={"environment": "production"}
)
)
print(f"Created API Center: {api_center.name}")
API Center の一覧表示
api_centers = client.services.list_by_subscription()
for api_center in api_centers:
print(f"{api_center.name} - {api_center.location}")
API の登録
from azure.mgmt.apicenter.models import Api, ApiKind, LifecycleStage
api = client.apis.create_or_update(
resource_group_name="my-resource-group",
service_name="my-api-center",
workspace_name="default",
api_name="my-api",
resource=Api(
title="My API",
description="A sample API for demonstration",
kind=ApiKind.REST,
lifecycle_stage=LifecycleStage.PRODUCTION,
terms_of_service={"url": "https://example.com/terms"},
contacts=[{"name": "API Team", "email": "[email protected]"}]
)
)
print(f"Registered API: {api.title}")
API バージョンの作成
from azure.mgmt.apicenter.models import ApiVersion, LifecycleStage
version = client.api_versions.create_or_update(
resource_group_name="my-resource-group",
service_name="my-api-center",
workspace_name="default",
api_name="my-api",
version_name="v1",
resource=ApiVersion(
title="Version 1.0",
lifecycle_stage=LifecycleStage.PRODUCTION
)
)
print(f"Created version: {version.title}")
API 定義の追加
from azure.mgmt.apicenter.models import ApiDefinition
definition = client.api_definitions.create_or_update(
resource_group_name="my-resource-group",
service_name="my-api-center",
workspace_name="default",
api_name="my-api",
version_name="v1",
definition_name="openapi",
resource=ApiDefinition(
title="OpenAPI Definition",
description="OpenAPI 3.0 specification"
)
)
API 仕様のインポート
from azure.mgmt.apicenter.models import ApiSpecImportRequest, ApiSpecImportSourceFormat
# Import from inline content
client.api_definitions.import_specification(
resource_group_name="my-resource-group",
service_name="my-api-center",
workspace_name="default",
api_name="my-api",
version_name="v1",
definition_name="openapi",
body=ApiSpecImportRequest(
format=ApiSpecImportSourceFormat.INLINE,
value='{"openapi": "3.0.0", "info": {"title": "My API", "version": "1.0"}, "paths": {}}'
)
)
API の一覧表示
apis = client.apis.list(
resource_group_name="my-resource-group",
service_name="my-api-center",
workspace_name="default"
)
for api in apis:
print(f"{api.name}: {api.title} ({api.kind})")
環境の作成
from azure.mgmt.apicenter.models import Environment, EnvironmentKind
environment = client.environments.create_or_update(
resource_group_name="my-resource-group",
service_name="my-api-center",
workspace_name="default",
environment_name="production",
resource=Environment(
title="Production",
description="Production environment",
kind=EnvironmentKind.PRODUCTION,
server={"type": "Azure API Management", "management_portal_uri": ["https://portal.azure.com"]}
)
)
デプロイの作成
from azure.mgmt.apicenter.models import Deployment, DeploymentState
deployment = client.deployments.create_or_update(
resource_group_name="my-resource-group",
service_name="my-api-center",
workspace_name="default",
api_name="my-api",
deployment_name="prod-deployment",
resource=Deployment(
title="Production Deployment",
description="Deployed to production APIM",
environment_id="/workspaces/default/environments/production",
definition_id="/workspaces/default/apis/my-api/versions/v1/definitions/openapi",
state=DeploymentState.ACTIVE,
server={"runtime_uri": ["https://api.example.com"]}
)
)
カスタムメタデータの定義
from azure.mgmt.apicenter.models import MetadataSchema
metadata = client.metadata_schemas.create_or_update(
resource_group_name="my-resource-group",
service_name="my-api-center",
metadata_schema_name="data-classification",
resource=MetadataSchema(
schema='{"type": "string", "title": "Data Classification", "enum": ["public", "internal", "confidential"]}'
)
)
クライアントの種類
| クライアント | 目的 |
|---|---|
ApiCenterMgmtClient | すべての操作のためのメインクライアント |
操作
| 操作グループ | 目的 |
|---|---|
services | API Center サービスの管理 |
workspaces | ワークスペースの管理 |
apis | API の登録と管理 |
api_versions | API バージョンの管理 |
api_definitions | API 定義の管理 |
deployments | デプロイの追跡 |
environments | 環境の管理 |
metadata_schemas | カスタムメタデータの定義 |
ベストプラクティス
- ワークスペースを使用する チームまたはドメインごとに API を整理します
- メタデータスキーマを定義する 一貫したガバナンスのために
- デプロイを追跡する API がどこで実行されているかを把握します
- 仕様をインポートする API の分析とリンティングを有効にします
- ライフサイクルステージを使用する API の成熟度を追跡します
- 連絡先を追加する API の所有権とサポートのために
使用する場合
このスキルは、概要に記載されたワークフローまたはアクションを実行する場合に適用されます。
制限事項
- このスキルは、タスクが上記の範囲に明確に一致する場合にのみ使用してください。
- 出力を環境固有の検証、テスト、専門家によるレビューの代替として扱わないでください。
- 必要な入力、権限、安全境界、成功基準が欠けている場合は、停止して確認を求めてください。
コメント
Markdown 対応