Use the Azure libraries (SDK) for Python
The open-source Azure libraries for Python simplify provisioning, managing, and using Azure resources from Python application code.
The details you really want to know
The Azure libraries are how you communicate with Azure services from Python code that you run either locally or in the cloud. (Whether you can run Python code within the scope of a particular service depends on whether that service itself currently supports Python.)
The libraries support Python 3.6 or later, and it is also tested with PyPy 5.4+.
The Azure SDK for Python is composed solely of over 180 individual Python libraries that relate to specific Azure services. There are no other tools in the "SDK".
When running code locally, authenticating with Azure relies on environment variables as described in How to authenticate Python apps to Azure services using the Azure SDK for Python.
To install library packages with pip, use
pip install <library_name>using library names from the package index. To install library packages in conda environments, use
conda install <package_name>using names from the Microsoft channel on anaconda.org. For more information, see Install Azure libraries.
There are distinct management and client libraries (sometimes referred to as "management plane" and "data plane" libraries). Each set serves different purposes and is used by different kinds of code. For more information, see the following sections later in this article:
To try the libraries for yourself, we first recommend setting up your local dev environment. Then you can try any of the following standalone examples (in any order): Example: Provision a resource group, Example: Provision and use Azure Storage, Example: Provision a web app and deploy code, Example: Provision and use a MySQL database, and Example: Provision a virtual machine.
Non-essential but still interesting details
Because the Azure CLI is written in Python using the management libraries, anything you can do with Azure CLI commands you can also do from a Python script. That said, the CLI commands provide many helpful features such as performing multiple tasks together, automatically handling asynchronous operations, formatting output like connection strings, and so on. Consequently, using the CLI (or its equivalent, Azure PowerShell) for automated provisioning and management scripts can be significantly more convenient than writing the equivalent Python code, unless you want to have a much more exacting degree of control over the process.
The Azure libraries for Python build on top of the underlying Azure REST API, allowing you to use those APIs through familiar Python paradigms. However, you can always use the REST API directly from Python code, if desired.
You can find the source code for the Azure libraries on https://github.com/Azure/azure-sdk-for-python. As an open-source project, contributions are welcome!
Although you can use the libraries with interpreters such as IronPython and Jython that we don't test against, you may encounter isolated issues and incompatibilities.
The source repo for the library API reference documentation resides on https://github.com/MicrosoftDocs/azure-docs-sdk-python/.
We're currently updating the Azure libraries for Python libraries to share common cloud patterns such as authentication protocols, logging, tracing, transport protocols, buffered responses, and retries.
This shared functionality is contained in the azure-core library.
The libraries that currently work with the Core library are listed on Azure SDK for Python latest releases. These libraries, primarily the client libraries, are sometimes referred to as "track 2".
The management libraries and any other that aren't yet updated are sometimes referred to as "track 1".
For details on the guidelines we apply to the libraries, see the Python Guidelines: Introduction.
Provision and manage Azure resources with management libraries
The SDK's management (or "management plane") libraries, the names of which all begin with
azure-mgmt-, help you create, provision and otherwise manage Azure resources from Python scripts. All Azure services have corresponding management libraries.
With the management libraries, you can write configuration and deployment scripts to perform the same tasks that you can through the Azure portal or the Azure CLI. (As noted earlier, the Azure CLI is written in Python and uses the management libraries to implement its various commands.)
The following examples illustrate how to use some of the primary management libraries:
- Provision a resource group
- List resource groups in a subscription
- Provision Azure Storage
- Provision a web app and deploy code
- Provision and query a database
- Provision a virtual machine
For details on working with each management library, see the README.md or README.rst file located in the library's project folder in the SDK GitHub repository. You can also find more code snippets in the reference documentation and the Azure Samples.
Migrating from older management libraries
If you are migrating code from older versions of the management libraries, see the following details:
- If you use the
ServicePrincipalCredentialsclass, see Authenticate with token credentials.
- The names of async APIs have changed as described on Library usage patterns - asynchronous operations. Simply said, the names of async APIs in newer libraries start with
begin_. In most cases, the API signature remains the same.
Connect to and use Azure resources with client libraries
The SDK's client (or "data plane") libraries help you write Python application code to interact with already-provisioned services. Client libraries exist only for those services that support a client API.
The article, Example: Use Azure Storage, provides a basic illustration of using client library.
Different Azure services also provide examples using these libraries. See the following index pages for other links:
- App hosting
- Cognitive Services
- Data solutions
- Identity and security
- Machine learning
- Messaging and IoT
- Other services
For details on working with each client library, see the README.md or README.rst file located in the library's project folder in the SDK's GitHub repository. You can also find more code snippets in the reference documentation and the Azure Samples.
Get help and connect with the SDK team
- Visit the Azure libraries for Python documentation
- Post questions to the community on Stack Overflow
- Open issues against the SDK on GitHub
- Mention @AzureSDK on Twitter
- Complete a short survey about the Azure SDK for Python
We strongly recommend doing a one-time setup of your local development environment so that you can easily use any of the Azure libraries for Python.
Submit and view feedback for