home / skills / sickn33 / antigravity-awesome-skills / azure-mgmt-apicenter-py

azure-mgmt-apicenter-py skill

/skills/azure-mgmt-apicenter-py

This skill helps you manage Azure API Center resources in Python, enabling efficient API governance, inventory, and metadata handling.

npx playbooks add skill sickn33/antigravity-awesome-skills --skill azure-mgmt-apicenter-py

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
6.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".
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
```

## Authentication

```python
from azure.identity import DefaultAzureCredential
from azure.mgmt.apicenter import ApiCenterMgmtClient
import os

client = ApiCenterMgmtClient(
    credential=DefaultAzureCredential(),
    subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]
)
```

## 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, 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}")
```

## Create API Version

```python
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}")
```

## Add API Definition

```python
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"
    )
)
```

## Import API Specification

```python
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": {}}'
    )
)
```

## 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

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"]}
    )
)
```

## Create Deployment

```python
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"]}
    )
)
```

## Define Custom Metadata

```python
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"]}'
    )
)
```

## 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. **Use workspaces** to organize APIs by team or domain
2. **Define metadata schemas** for consistent governance
3. **Track deployments** to understand where APIs are running
4. **Import specifications** to enable API analysis and linting
5. **Use lifecycle stages** to track API maturity
6. **Add contacts** for API ownership and support

Overview

This skill provides a Python SDK wrapper for managing APIs in Azure API Center. It helps teams register APIs, manage versions and definitions, track deployments, and enforce governance across workspaces and environments. Use it to automate API inventory, metadata schemas, and lifecycle tracking.

How this skill works

The skill instantiates ApiCenterMgmtClient with Azure credentials and subscription context, then calls service groups like services, apis, api_versions, api_definitions, deployments, environments, and metadata_schemas. It supports creating API Centers, registering APIs and versions, importing OpenAPI specs, creating deployments and environments, and defining custom metadata schemas for governance. Operations are accessible via typed model objects from azure.mgmt.apicenter.models.

When to use it

  • Automate onboarding and cataloging of new APIs across teams
  • Enforce metadata schemas and governance rules for APIs
  • Import and validate OpenAPI/Swagger specifications programmatically
  • Manage API versions and deployments across environments
  • Centralize API inventory and contacts for audit and support

Best practices

  • Organize APIs into workspaces by team or domain to limit blast radius
  • Define and enforce metadata schemas for consistent classification and governance
  • Import full API specifications (OpenAPI) to enable analysis and linting
  • Use lifecycle_stage and deployment tracking to reflect maturity and runtime status
  • Store AZURE_SUBSCRIPTION_ID in environment variables and use DefaultAzureCredential for secure auth

Example use cases

  • Provision a new API Center and register a suite of internal APIs with ownership contacts
  • Automate import of OpenAPI specs into API Center and create versioned definitions for CI pipelines
  • Create production and staging environments and deploy specific API versions to each for release management
  • Define a data-classification metadata schema and attach it to APIs for compliance reporting
  • List and export API inventory across subscription for security audits and inventory reconciliation

FAQ

How do I authenticate the client?

Use azure.identity.DefaultAzureCredential and set AZURE_SUBSCRIPTION_ID in environment variables; the credential will pick up managed identity, CLI, or environment credentials.

Can I import OpenAPI specifications programmatically?

Yes. Use api_definitions.import_specification with ApiSpecImportRequest and set format to INLINE or an appropriate source format to import OpenAPI content.