azure-mgmt-apicenter-py
Azure API Center Management SDK for Python. Use for managing API inventory, metadata, and governance across your organization. Triggers: "azure-mgmt-apicenter", "ApiCenterMgmtClient", "API Center", "API inventory", "API governance".
Install
npx skills add https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-python/skills/azure-mgmt-apicenter-py
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install microsoft-skills@llmmart
git clone https://github.com/microsoft/skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole microsoft/skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Azure API Center Management SDK for Python
Manage API inventory, metadata, and governance in Azure API Center.
Installation
pip install azure-mgmt-apicenter
pip install azure-identity
Environment Variables
AZURE_SUBSCRIPTION_ID=your-subscription-id # 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.
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.mgmt.apicenter import ApiCenterMgmtClient
import os
# 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()
with ApiCenterMgmtClient(
credential=credential,
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]
) as client:
# Use `client` for all subsequent operations (see examples below)
...
Create 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}")
List API Centers
api_centers = client.services.list_by_subscription()
for api_center in api_centers:
print(f"{api_center.name} - {api_center.location}")
Register an API
from azure.mgmt.apicenter.models import Api, ApiKind, ApiProperties
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(
properties=ApiProperties(
title="My API",
description="A sample API for demonstration",
kind=ApiKind.REST,
terms_of_service={"url": "https://example.com/terms"},
contacts=[{"name": "API Team", "email": "api-team@example.com"}],
)
),
)
print(f"Registered API: {api.properties.title}")
Create API Version
from azure.mgmt.apicenter.models import ApiVersion, ApiVersionProperties, 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(
properties=ApiVersionProperties(
title="Version 1.0",
lifecycle_stage=LifecycleStage.PRODUCTION,
)
),
)
print(f"Created version: {version.properties.title}")
Add API Definition
from azure.mgmt.apicenter.models import ApiDefinition, ApiDefinitionProperties
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(
properties=ApiDefinitionProperties(
title="OpenAPI Definition",
description="OpenAPI 3.0 specification",
)
),
)
Import API Specification
from azure.mgmt.apicenter.models import ApiSpecImportRequest, ApiSpecImportSourceFormat
# Import from inline content
client.api_definitions.begin_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": {}}',
)
).result()
List APIs
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})")
Create Environment
from azure.mgmt.apicenter.models import Environment, EnvironmentKind, EnvironmentProperties
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(
properties=EnvironmentProperties(
title="Production",
description="Production environment",
kind=EnvironmentKind.PRODUCTION,
server={"type": "Azure API Management", "management_portal_uri": ["https://portal.azure.com"]},
)
),
)
Create Deployment
from azure.mgmt.apicenter.models import Deployment, DeploymentProperties, 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(
properties=DeploymentProperties(
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"]},
)
),
)
Define Custom Metadata
from azure.mgmt.apicenter.models import MetadataSchema, MetadataSchemaProperties
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(
properties=MetadataSchemaProperties(
schema='{"type": "string", "title": "Data Classification", "enum": ["public", "internal", "confidential"]}'
)
),
)
Client Types
| Client | Purpose |
|---|---|
ApiCenterMgmtClient |
Main client for all operations |
Operations
| Operation Group | Purpose |
|---|---|
services |
API Center service management |
workspaces |
Workspace management |
apis |
API registration and management |
api_versions |
API version management |
api_definitions |
API definition management |
deployments |
Deployment tracking |
environments |
Environment management |
metadata_schemas |
Custom metadata definitions |
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 workspaces to organize APIs by team or domain
- Define metadata schemas for consistent governance
- Track deployments to understand where APIs are running
- Import specifications to enable API analysis and linting
- Use lifecycle stages to track API maturity
- Add contacts for API ownership and support
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. |
Files (skills)
-
references
-
capabilities.md 2.1 KB
# azure-mgmt-apicenter-py capability coverage **SDK/package**: `azure-mgmt-apicenter` This index maps hero scenarios in `SKILL.md` and links non-hero scenarios documented in dedicated reference files. ## Hero scenarios covered in SKILL.md - `Create API Center` - `List API Centers` - `Register an API` - `Create API Version` ## Non-hero scenarios - `Add API Definition`: Dedicated example and implementation notes. See: [`non-hero-scenarios.md#add-api-definition`](non-hero-scenarios.md#add-api-definition) - `Import API Specification`: Dedicated example and implementation notes. See: [`non-hero-scenarios.md#import-api-specification`](non-hero-scenarios.md#import-api-specification) - `List APIs`: Dedicated example and implementation notes. See: [`non-hero-scenarios.md#list-apis`](non-hero-scenarios.md#list-apis) - `Create Environment`: Dedicated example and implementation notes. See: [`non-hero-scenarios.md#create-environment`](non-hero-scenarios.md#create-environment) - `Create Deployment`: Dedicated example and implementation notes. See: [`non-hero-scenarios.md#create-deployment`](non-hero-scenarios.md#create-deployment) - `Define Custom Metadata`: Dedicated example and implementation notes. See: [`non-hero-scenarios.md#define-custom-metadata`](non-hero-scenarios.md#define-custom-metadata) - `Client Types`: | Client | Purpose | See: [`non-hero-scenarios.md#client-types`](non-hero-scenarios.md#client-types) - `Operations`: | Operation Group | Purpose | See: [`non-hero-scenarios.md#operations`](non-hero-scenarios.md#operations) ## Related deep-dive references - [`non-hero-scenarios.md`](non-hero-scenarios.md): Dedicated non-hero examples and implementation notes. ## API breadth checklist - Verify client/auth mode for the environment before coding. - Confirm operation-group/method names against current Microsoft Learn API reference. - For Python SDKs with both sync and async clients, document both forms without a blanket preference. - Include cleanup/delete paths for created resources in examples. - Prefer idempotent create/update operations where available. - Validate paging/LRO/error-handling patterns for production paths. -
non-hero-scenarios.md 4 KB
# azure-mgmt-apicenter-py non-hero scenarios These scenarios are intentionally separate from hero flows in `SKILL.md`. They cover secondary/advanced patterns typically used after the primary end-to-end path is working. ## Add API Definition ```python from azure.mgmt.apicenter.models import ApiDefinition, ApiDefinitionProperties 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( properties=ApiDefinitionProperties( title="OpenAPI Definition", description="OpenAPI 3.0 specification", ) ), ) ``` ## Import API Specification ```python from azure.mgmt.apicenter.models import ApiSpecImportRequest, ApiSpecImportSourceFormat # Import from inline content client.api_definitions.begin_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": {}}', ) ).result() ``` ## List APIs ```python 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.properties.title} ({api.properties.kind})") ``` ## Create Environment ```python from azure.mgmt.apicenter.models import Environment, EnvironmentKind, EnvironmentProperties 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( properties=EnvironmentProperties( title="Production", description="Production environment", kind=EnvironmentKind.PRODUCTION, server={"type": "Azure API Management", "management_portal_uri": ["https://portal.azure.com"]}, ) ), ) ``` ## Create Deployment ```python from azure.mgmt.apicenter.models import Deployment, DeploymentProperties, 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( properties=DeploymentProperties( 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"]}, ) ), ) ``` ## Define Custom Metadata ```python from azure.mgmt.apicenter.models import MetadataSchema, MetadataSchemaProperties 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( properties=MetadataSchemaProperties( schema='{"type": "string", "title": "Data Classification", "enum": ["public", "internal", "confidential"]}' ) ), ) ``` ## Client Types | Client | Purpose | |--------|---------| | `ApiCenterMgmtClient` | Main client for all operations | ## Operations | Operation Group | Purpose | |----------------|---------| | `services` | API Center service management | | `workspaces` | Workspace management | | `apis` | API registration and management | | `api_versions` | API version management | | `api_definitions` | API definition management | | `deployments` | Deployment tracking | | `environments` | Environment management | | `metadata_schemas` | Custom metadata definitions |
-
-
SKILL.md 9.2 KB
--- name: azure-mgmt-apicenter-py description: | Azure API Center Management SDK for Python. Use for managing API inventory, metadata, and governance across your organization. Triggers: "azure-mgmt-apicenter", "ApiCenterMgmtClient", "API Center", "API inventory", "API governance". license: MIT metadata: author: Microsoft version: "1.0.0" package: azure-mgmt-apicenter --- # Azure API Center Management SDK for Python Manage API inventory, metadata, and governance in Azure API Center. ## Installation ```bash pip install azure-mgmt-apicenter pip install azure-identity ``` ## Environment Variables ```bash AZURE_SUBSCRIPTION_ID=your-subscription-id # 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:** > > 1. **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: `DefaultAzureCredential` works as-is. > - Production: set `AZURE_TOKEN_CREDENTIALS=prod` (or `AZURE_TOKEN_CREDENTIALS=<specific_credential>`) to constrain the credential chain to production-safe credentials. > 2. **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:` **and** `async with DefaultAzureCredential() as credential:` (from `azure.identity.aio`) > > Snippets may abbreviate this setup, but production code should always follow both rules. ```python from azure.identity import DefaultAzureCredential, ManagedIdentityCredential from azure.mgmt.apicenter import ApiCenterMgmtClient import os # 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() with ApiCenterMgmtClient( credential=credential, subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"] ) as client: # Use `client` for all subsequent operations (see examples below) ... ``` ## Create API Center ```python 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}") ``` ## List API Centers ```python api_centers = client.services.list_by_subscription() for api_center in api_centers: print(f"{api_center.name} - {api_center.location}") ``` ## Register an API ```python from azure.mgmt.apicenter.models import Api, ApiKind, ApiProperties 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( properties=ApiProperties( title="My API", description="A sample API for demonstration", kind=ApiKind.REST, terms_of_service={"url": "https://example.com/terms"}, contacts=[{"name": "API Team", "email": "api-team@example.com"}], ) ), ) print(f"Registered API: {api.properties.title}") ``` ## Create API Version ```python from azure.mgmt.apicenter.models import ApiVersion, ApiVersionProperties, 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( properties=ApiVersionProperties( title="Version 1.0", lifecycle_stage=LifecycleStage.PRODUCTION, ) ), ) print(f"Created version: {version.properties.title}") ``` ## Add API Definition ```python from azure.mgmt.apicenter.models import ApiDefinition, ApiDefinitionProperties 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( properties=ApiDefinitionProperties( title="OpenAPI Definition", description="OpenAPI 3.0 specification", ) ), ) ``` ## Import API Specification ```python from azure.mgmt.apicenter.models import ApiSpecImportRequest, ApiSpecImportSourceFormat # Import from inline content client.api_definitions.begin_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": {}}', ) ).result() ``` ## List APIs ```python 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})") ``` ## Create Environment ```python from azure.mgmt.apicenter.models import Environment, EnvironmentKind, EnvironmentProperties 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( properties=EnvironmentProperties( title="Production", description="Production environment", kind=EnvironmentKind.PRODUCTION, server={"type": "Azure API Management", "management_portal_uri": ["https://portal.azure.com"]}, ) ), ) ``` ## Create Deployment ```python from azure.mgmt.apicenter.models import Deployment, DeploymentProperties, 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( properties=DeploymentProperties( 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"]}, ) ), ) ``` ## Define Custom Metadata ```python from azure.mgmt.apicenter.models import MetadataSchema, MetadataSchemaProperties 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( properties=MetadataSchemaProperties( schema='{"type": "string", "title": "Data Classification", "enum": ["public", "internal", "confidential"]}' ) ), ) ``` ## Client Types | Client | Purpose | |--------|---------| | `ApiCenterMgmtClient` | Main client for all operations | ## Operations | Operation Group | Purpose | |----------------|---------| | `services` | API Center service management | | `workspaces` | Workspace management | | `apis` | API registration and management | | `api_versions` | API version management | | `api_definitions` | API definition management | | `deployments` | Deployment tracking | | `environments` | Environment management | | `metadata_schemas` | Custom metadata definitions | ## Best Practices 1. **Pick sync OR async and stay consistent.** Do not mix `azure.xxx` sync clients with `azure.xxx.aio` async clients in the same call path. Choose one mode per module. 2. **Always use context managers for clients and async credentials.** Wrap every client in `with Client(...) as client:` (sync) or `async with Client(...) as client:` (async). For async `DefaultAzureCredential` from `azure.identity.aio`, also use `async with credential:` so tokens and transports are cleaned up. 3. **Use workspaces** to organize APIs by team or domain 4. **Define metadata schemas** for consistent governance 5. **Track deployments** to understand where APIs are running 6. **Import specifications** to enable API analysis and linting 7. **Use lifecycle stages** to track API maturity 8. **Add contacts** for API ownership and support ## Reference Files | File | Contents | |------|----------| | [references/capabilities.md](references/capabilities.md) | Additional non-hero capabilities, operation-group coverage, and production checklists. | | [references/non-hero-scenarios.md](references/non-hero-scenarios.md) | Dedicated non-hero examples for secondary/advanced scenarios. |
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.