Microsoft Azure API Management Client Library for Python providing comprehensive SDK functionality for managing Azure API Management services.
npx @tessl/cli install tessl/pypi-azure-mgmt-apimanagement@5.0.0Microsoft Azure API Management Client Library for Python provides comprehensive SDK functionality for programmatically managing and configuring Azure API Management instances. This library enables developers to automate API lifecycle management, implement governance policies, configure authentication systems, manage developer portals, and monitor API usage through Python applications.
pip install azure-mgmt-apimanagementisodate>=0.6.1, typing-extensions>=4.6.0, azure-common>=1.1, azure-mgmt-core>=1.3.2, azure-identity (for authentication)from azure.mgmt.apimanagement import ApiManagementClient
from azure.identity import DefaultAzureCredentialfrom azure.mgmt.apimanagement import ApiManagementClient
from azure.identity import DefaultAzureCredential
# Create client with authentication
credential = DefaultAzureCredential()
client = ApiManagementClient(
credential=credential,
subscription_id="your-subscription-id"
)
# List API Management services
services = list(client.api_management_service.list_by_subscription())
for service in services:
print(f"Service: {service.name}, Location: {service.location}")
# Get a specific API Management service
service = client.api_management_service.get(
resource_group_name="my-resource-group",
service_name="my-apim-service"
)
# List APIs in the service
apis = list(client.api.list_by_service(
resource_group_name="my-resource-group",
service_name="my-apim-service"
))
for api in apis:
print(f"API: {api.name}, Path: {api.path}")The Azure API Management Client Library follows Azure SDK design principles:
ApiManagementClient serves as the main entry point providing access to all operation groupsThe library provides both synchronous and asynchronous clients, comprehensive error handling, automatic retries, logging integration, and follows Azure ARM (Azure Resource Manager) patterns for consistent resource management across Azure services.
Core API Management service lifecycle operations including creating, updating, configuring, and monitoring API Management instances. Includes service-level settings, SKU management, network configuration, and backup/restore capabilities.
class ApiManagementServiceOperations:
def get(self, resource_group_name: str, service_name: str, **kwargs) -> ApiManagementServiceResource: ...
def begin_create_or_update(self, resource_group_name: str, service_name: str, parameters: ApiManagementServiceResource, **kwargs) -> LROPoller[ApiManagementServiceResource]: ...
def begin_update(self, resource_group_name: str, service_name: str, parameters: ApiManagementServiceUpdateParameters, **kwargs) -> LROPoller[ApiManagementServiceResource]: ...
def begin_delete(self, resource_group_name: str, service_name: str, **kwargs) -> LROPoller[None]: ...
def list_by_subscription(self, **kwargs) -> ItemPaged[ApiManagementServiceResource]: ...
def list_by_resource_group(self, resource_group_name: str, **kwargs) -> ItemPaged[ApiManagementServiceResource]: ...Comprehensive API lifecycle management including API creation, versioning, revisions, operations, schemas, policies, and export/import capabilities. Supports REST, SOAP, GraphQL, and WebSocket APIs.
class ApiOperations:
def get(self, resource_group_name: str, service_name: str, api_id: str, **kwargs) -> ApiContract: ...
def begin_create_or_update(self, resource_group_name: str, service_name: str, api_id: str, parameters: ApiCreateOrUpdateParameter, **kwargs) -> LROPoller[ApiContract]: ...
def begin_update(self, resource_group_name: str, service_name: str, api_id: str, parameters: ApiUpdateContract, **kwargs) -> LROPoller[ApiContract]: ...
def delete(self, resource_group_name: str, service_name: str, api_id: str, **kwargs) -> None: ...
def list_by_service(self, resource_group_name: str, service_name: str, **kwargs) -> ItemPaged[ApiContract]: ...The library provides extensive additional operations for comprehensive API Management functionality:
These operations follow the same patterns as the core capabilities documented above, with comprehensive CRUD operations, entity tag support, and long-running operation handling where applicable.
Comprehensive policy system for implementing cross-cutting concerns including authentication, rate limiting, transformation, caching, and routing. Supports policies at global, product, API, and operation levels.
class PolicyOperations:
def get(self, resource_group_name: str, service_name: str, policy_id: str, **kwargs) -> PolicyContract: ...
def create_or_update(self, resource_group_name: str, service_name: str, policy_id: str, parameters: PolicyContract, **kwargs) -> PolicyContract: ...
def delete(self, resource_group_name: str, service_name: str, policy_id: str, **kwargs) -> None: ...
def list_by_service(self, resource_group_name: str, service_name: str, **kwargs) -> ItemPaged[PolicyContract]: ...
class PolicyFragmentOperations:
def get(self, resource_group_name: str, service_name: str, policy_fragment_id: str, **kwargs) -> PolicyFragmentContract: ...
def begin_create_or_update(self, resource_group_name: str, service_name: str, policy_fragment_id: str, parameters: PolicyFragmentContract, **kwargs) -> LROPoller[PolicyFragmentContract]: ...
def delete(self, resource_group_name: str, service_name: str, policy_fragment_id: str, **kwargs) -> None: ...
def list_by_service(self, resource_group_name: str, service_name: str, **kwargs) -> ItemPaged[PolicyFragmentContract]: ...The library provides full async/await support through the aio module:
from azure.mgmt.apimanagement.aio import ApiManagementClient
from azure.identity.aio import DefaultAzureCredential
async def manage_apis():
credential = DefaultAzureCredential()
async with ApiManagementClient(credential, "subscription-id") as client:
# Async operations
async for service in client.api_management_service.list_by_subscription():
print(f"Service: {service.name}")The library uses Azure Core exceptions for consistent error handling:
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
try:
service = client.api_management_service.get("rg", "service-name")
except ResourceNotFoundError:
print("Service not found")
except HttpResponseError as e:
print(f"HTTP error: {e.status_code} - {e.message}")All data models, enums, and type definitions are available through the models module:
from azure.mgmt.apimanagement.models import (
ApiManagementServiceResource,
ApiContract,
ApiCreateOrUpdateParameter,
ProductContract,
UserContract,
GroupContract,
PolicyContract,
PolicyFragmentContract,
BackendContract,
OperationContract,
SchemaContract,
# ... and 470+ other model classes
)
# For long-running operations and paging
from azure.core.polling import LROPoller
from azure.core.paging import ItemPaged