title | description | ms.date | ms.topic |
---|---|---|---|
Azure SDK for Python |
Overview of the features and capabilities of the Azure SDK for Python that helps developers be more productive when working with Azure services. |
10/30/2019 |
conceptual |
The Azure SDK for Python simplifies using and managing Azure resources from Python application code. The SDK supports Python 2.7 and Python 3.5.3 or later.
You install the SDK by installing any of its individual component libraries by using pip install <library>
. You can see the list of libraries on the Azure SDK for Python package index
For more detailed instructions for installing libraries and importing them into projects, see Install the SDK. Then review the Get started with the SDK to set up your authentication and run sample code against your own Azure subscription.
Tip
For information on changes in the SDK, see the SDK release notes.
A number of client libraries in the SDK help you connect to existing Azure resources and use them in your apps, such as uploading files, accessing table data, or working with the various Azure Cognitive Services. With the SDK you work with those resources using familiar Python programming paradigms rather than using the service's generic REST API.
For example, suppose you want to upload a blob to an Azure Storage account that you've previously provisioned. The first step is to install the appropriate library:
pip install azure-storage-blob
Next, import the library in your code:
from azure.storage.blob import BlobClient
Finally, use the library's API to connect to and upload the data. In this example, the connection string and container name are already provisioned in your storage account. The blob name is the name you assign to the uploaded data:
blob = BlobClient.from_connection_string("my_connection_string", container="mycontainer", blob="my_blob")
with open("./SampleSource.txt", "rb") as data:
blob.upload_blob(data)
For details on working with each specific library, see the README.md or README.rst file located in the library's project folder in our GitHub repository. Also refer to the available Azure Samples.
You can also find additional code snippets in the reference documentation
We are currently updating our Python client libraries to share core functionality such as retries, logging, transport protocols, authentication protocols, etc. This shared functionality is contained in the azure-core library. For details on the library and its guidelines, see the Python Guidelines: Introduction.
The libraries that currently work with the Core library are as follows:
azure-storage-blob
azure-storage-queue
azure-keyvault-keys
azure-keyvault-secrets
The Azure SDK for Python also includes many libraries to help you create, provision, and otherwise manage Azure resources themselves. We refer to these as management libraries. Each management library is named azure-mgmt-<service name>
. With the management libraries, you can write Python code to accomplish the same tasks that you can using the Azure portal or the Azure CLI.
For example, suppose you want to create a SQL Server instance. First, install the appropriate management library:
pip install azure-mgmt-sql
In your Python code, import the library:
from azure.mgmt.sql import SqlManagementClient
Next, create the management client object using your credentials and Azure subscription ID:
sql_client = SqlManagementClient(credentials, subscription_id)
Finally, use that client object to create the resource, using an appropriate resource group name, server name, location, and administrator credentials:
server = sql_client.servers.create_or_update(
'myresourcegroup',
'myservername',
{
'location': 'eastus',
'version': '12.0', # Required for create
'administrator_login': 'mysecretname', # Required for create
'administrator_login_password': 'HusH_Sec4et' # Required for create
}
)
As with the client libraries, you can find details on working with each management library in the README.md or README.rst file located in the library's project folder in our GitHub repository.
You can also find additional code snippets in the reference documentation.
- Visit the Azure SDK for Python documentation
- Post questions to the community on Stack Overflow
- Open issues against the SDK on GitHub
- Tweet at @AzureSDK