Azure SDK for Python¶
Important
The most part of this documentation has moved to https://docs.microsoft.com/python/azure
The Azure SDK for Python is a set of libraries which allow you to work on Azure for your management, runtime or data needs.
For a more general view of Azure and Python, you can go on the Python Developer Center for Azure
Example Usage¶
This example shows:
- Authentication on Azure using an AD in your subscription,
- Creation of a Resource Group and a Storage account,
- Upload a simple “Hello world” HTML page and gives you the URL to get it.
from azure.common.credentials import UserPassCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient
from azure.storage import CloudStorageAccount
from azure.storage.blob.models import ContentSettings, PublicAccess
credentials = UserPassCredentials('user@domain.com', 'my_smart_password')
subscription_id = '33333333-3333-3333-3333-333333333333'
resource_client = ResourceManagementClient(credentials, subscription_id)
storage_client = StorageManagementClient(credentials, subscription_id)
resource_group_name = 'my_resource_group'
storage_account_name = 'myuniquestorageaccount'
resource_client.resource_groups.create_or_update(
resource_group_name,
{
'location':'westus'
}
)
async_create = storage_client.storage_accounts.create(
resource_group_name,
storage_account_name,
{
'location':'westus',
'kind':'storage',
'sku': {
'name':'standard_ragrs'
}
}
)
async_create.wait()
storage_keys = storage_client.storage_accounts.list_keys(resource_group_name, storage_account_name)
storage_keys = {v.key_name: v.value for v in storage_keys.keys}
storage_client = CloudStorageAccount(storage_account_name, storage_keys['key1'])
blob_service = storage_client.create_block_blob_service()
blob_service.create_container(
'mycontainername',
public_access=PublicAccess.Blob
)
blob_service.create_blob_from_bytes(
'mycontainername',
'myblobname',
b'<center><h1>Hello World!</h1></center>',
content_settings=ContentSettings('text/html')
)
print(blob_service.make_blob_url('mycontainername', 'myblobname'))
Installation¶
Overview¶
You can install individually each library for each Azure service:
$ pip install azure-batch # Install the latest Batch runtime library
$ pip install azure-mgmt-scheduler # Install the latest Storage management library
Preview packages can be installed using the --pre
flag:
$ pip install --pre azure-mgmt-compute # will install only the latest Compute Management library
More details and information about the available libraries and their status can be found in the Installation Page
The azure
meta-package¶
You can also install a set of Azure libraries in a single line using the azure
meta-package. Since not all packages in this meta-package are
published as stable yet, the azure
meta-package is still in preview.
However, the core packages, from code quality/completeness perspectives can at this time be considered “stable”
- it will be officially labeled as such in sync with other languages as soon as possible.
We are not planning on any further major changes until then.
Since it’s a preview release, you need to use the --pre
flag:
$ pip install --pre azure
or directly
$ pip install azure==2.0.0rc6
Important
The azure meta-package 1.0.3 is deprecated and is not working anymore.
Features¶
Azure Resource Management¶
All documentation of management libraries for Azure are on this website. This includes:
- Authorization : Permissions, roles and more
- Batch : Manage Batch accounts and applications
- Content Delivery Network : Profiles, endpoints creation and more
- Cognitive Services : Create CS accounts and more
- Commerce - Billing API : RateCard and Usage Billing API
- Compute : Create virtual machines and more
- Data Lake Analytics : Manage account, job, catalog and more
- Data Lake Store : Manage account and more
- DevTestLabs : Create labs and more
- DNS : Create DNS zone, record set and more
- IoTHub : Create IoTHub account and more
- KeyVault : Create vaults and more
- App Service : Create App plan, Web Apps, Logic Apps and more
- Media Services : Create account and more
- Network : Create virtual networks, network interfaces, public IPs and more
- Notification Hubs : Namespaces, hub creation/deletion and more
- PowerBI Embedded : Create account and more
- Redis Cache : Create cache and more
- Resource Management:
- resources : create resource groups, register providers and more
- features : manage features of provider and more
- locks : manage resource group lock and more
- subscriptions : manage subscriptions and more
- Scheduler : Create job collections, create job and more
- Server Manager : Create gateways, nodes and more
- SQL Database : Create servers, databases nodes and more
- Storage : Create storage accounts, list keys, and more
- Traffic Manager : Create endpoints, profiles and more
Azure Runtime¶
Some documentation of data libraries are on this website. This includes:
Service Bus using HTTP.
Note
For critical performance issue, the Service Bus team currently recommends AMQP.
These Azure services have Python data libraries which are directly hosted by the service team or are extensively documented on the Azure documentation website:
Azure Service Management¶
Note
The Service Management SDK is deprecated and no more features will be added.
This page describes the usage and detailed features of Azure Service Management SDK. At a glance:
- storage accounts: create, update, delete, list, regenerate keys
- affinity groups: create, update, delete, list, get properties
- locations: list
- hosted services: create, update, delete, list, get properties
- deployment: create, get, delete, swap, change configuration, update status, upgrade, rollback
- role instance: reboot, reimage
- discover addresses and ports for the endpoints of other role instances in your service
- get configuration settings and access local resources
- get role instance information for current role and other role instances
- query and set the status of the current role
System Requirements:¶
The supported Python versions are 2.7.x, 3.3.x, 3.4.x, 3.5.x and 3.6.x To download Python, please visit https://www.python.org/download/
We recommend Python Tools for Visual Studio as a development environment for developing your applications. Please visit http://aka.ms/python for more information.
Need Help?:¶
Be sure to check out the Microsoft Azure Developer Forums on Stack Overflow if you have trouble with the provided code.
Contribute Code or Provide Feedback:¶
If you would like to become an active contributor to this project please follow the instructions provided in Microsoft Azure Projects Contribution Guidelines.
If you encounter any bugs with the library please file an issue in the Issues section of the project.
Indices and tables¶
User Documentation
Management Documentation
- Resource Management
- Apps Management
- Batch Management
- Content Delivery Network Management
- Compute and Network Management
- Redis Cache Management
- Scheduler Management
- Storage Management
- Authorization Management
- Cognitive Services Management
- Commerce - Billing API
- Azure Data Lake Management Analytics
- Azure Data Lake Management Store
- DevTestLabs Management
- DNS Management
- IoTHub Management
- KeyVault Management
- Managed Disks
- Notification Hubs Management
- PowerBI Embedded Management
- ServerManager Management
- SQL Database Management
- Traffic Manager Management
- Service Management (Legacy)
Runtime Documentation
Developer Documentation
- azure.common package
- azure.batch package
- azure.graphrbac package
- azure.keyvault package
- azure.mgmt.authorization package
- azure.mgmt.batch package
- azure.mgmt.billing package
- azure.mgmt.cdn package
- azure.mgmt.cognitiveservices package
- azure.mgmt.commerce package
- azure.mgmt.compute.compute package
- azure.mgmt.compute.containerservice package
- azure.mgmt.consumption package
- azure.mgmt.containerregistry.v2017_03_01 package
- azure.mgmt.containerregistry.v2017_06_01_preview package
- azure.mgmt.datalake.analytics.account package
- azure.mgmt.datalake.analytics.catalog package
- azure.mgmt.datalake.analytics.job package
- azure.mgmt.datalake.store package
- azure.mgmt.devtestlabs package
- azure.mgmt.dns package
- azure.mgmt.documentdb package
- azure.mgmt.eventhub package
- azure.mgmt.iothub package
- azure.mgmt.keyvault package
- azure.mgmt.logic package
- azure.mgmt.media package
- azure.mgmt.monitor package
- azure.mgmt.network package
- azure.mgmt.notificationhubs package
- azure.mgmt.powerbiembedded package
- azure.mgmt.rdbms.mysql package
- azure.mgmt.rdbms.postgresql package
- azure.mgmt.recoveryservicesbackup package
- azure.mgmt.redis package
- azure.mgmt.resource.features package
- azure.mgmt.resource.links package
- azure.mgmt.resource.locks package
- azure.mgmt.resource.managedapplications package
- azure.mgmt.resource.policy package
- azure.mgmt.resource.resources package
- azure.mgmt.resource.subscriptions package
- azure.mgmt.scheduler package
- azure.mgmt.search package
- azure.mgmt.servermanager package
- azure.mgmt.servicebus package
- azure.mgmt.sql package
- azure.mgmt.storage package
- azure.mgmt.trafficmanager package
- azure.mgmt.web package
- azure.monitor package
- azure.servicefabric package
- azure.servicebus package
- azure.servicemanagement package
- Submodules
- azure.servicemanagement.constants module
- azure.servicemanagement.models module
- azure.servicemanagement.publishsettings module
- azure.servicemanagement.schedulermanagementservice module
- azure.servicemanagement.servicebusmanagementservice module
- azure.servicemanagement.servicemanagementclient module
- azure.servicemanagement.servicemanagementservice module
- azure.servicemanagement.sqldatabasemanagementservice module
- azure.servicemanagement.websitemanagementservice module
- Module contents
- Submodules