你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Azure Resources libraries for python
Overview
Deploy, monitor, and manage resources in groups with Azure Resource Manager.
Management API
Use the management API to create resource groups and deploy resources from templates.
pip install azure-mgmt-resource
pip install azure-identity
Example
Create a new resource group in the Azure Eastern US region.
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
import os
LOCATION = 'eastus'
GROUP_NAME ='sample_resource_group'
sub_id = os.getenv("AZURE_SUBSCRIPTION_ID")
client = ResourceManagementClient(credential=DefaultAzureCredential(), subscription_id=sub_id)
client.resource_groups.create_or_update(GROUP_NAME, {'location': LOCATION})
Samples
Manage Azure resources and resource groups
View the complete list of Azure Resource Manager samples.