Get started with Python on Azure
If you're new to developing applications for the cloud, this short series of 8 articles is the best place to start.
- Part 1: Azure for developers overview
- Part 2: Key Azure services for developers
- Part 3: Hosting applications on Azure
- Part 4: Connect your app to Azure services
- Part 5: How do I create and manage resources in Azure?
- Part 6: Key concepts for building Azure apps
- Part 7: How am I billed?
- Part 8: Versioning policy for Azure services, SDKs, and CLI tools
Create an Azure Account
To develop Python applications with Azure, you need an Azure account. Your Azure account is the credentials you use to sign-in to Azure with and what you use to create Azure resources.
If you're using Azure at work, talk to your company's cloud administrator to get your credentials used to sign-in to Azure.
Otherwise, you can create an Azure account for free and receive 12 months of popular services for free and a $200 credit to explore Azure for 30 days.
Create and manage resources
To use Azure resources like databases, message queues, file storage, and so on, you must first create an instance of the resource. Creating resources involves:
- choosing capacity or computing options
- adding the new resource to a resource group
- selecting the region of the world where the service runs
- giving the service a unique name
There are several tools you can use create and manage Azure resources, depending on your scenario:
- Azure portal - If you're new to Azure and want a web-based user interface to create and manage a couple of resources.
- Azure CLI - If you're more comfortable with command line interfaces.
- Azure PowerShell - If you prefer a PowerShell style syntax in their CLI.
- Azure Developer CLI - When you want to create repeatable deployments involving many Azure resources with intricate dependencies. Requires learning Bicep templates an imperative language.
- Azure Tools extension pack - The extension pack contains extensions for working with some of the most popular Azure services in one convenient package.
You can also use the Azure Management Libraries for Python to create and manage resources. The management libraries allow you to use Python to implement custom deployment and management functionality. Here are a few articles that can help you get started:
- Create a resource group
- List groups and resources
- Create Azure storage
- Create and deploy a web app
- Create and query a database
- Create a virtual machine
Write your Python app
Developing on Azure requires Python 3.8 or higher. To verify the version of Python on your workstation, in a console window type the command python3 --version
for macOS/Linux or py --version
for Windows.
Use your favorite tools to write your Python app. If you use Visual Studio Code, you should try the Python extension for Visual Studio Code.
Most of the instructions in this set of articles use a virtual environment because it's a best practice. Feel free to use any virtual environment you want, but the article instructions standardize on venv
.
Use client libraries
As you're getting started, the articles instruct you on which Python on Azure libraries to install and reference using the pip
utility.
At some point, you might want to install and reference the Azure SDK for Python client libraries without follow the instructions in an article. The Azure SDK Overview is a great starting point.
Authenticate your app to Azure
When you use the Azure SDK for Python, your app must authenticate itself. How your app authenticates depends on whether you're running your app locally during development and testing, hosting the app on your own servers, or hosting the app in Azure. Read Authenticate Python apps to Azure services by using the Azure SDK for Python to understand more about authentication on Azure.
You'll also need to set up access policies that control what identities (service principals and/or application IDs) are able to access those resources. Access policies are managed through Azure Role-Based Access Control (RBAC); some services have more specific access controls as well. As a cloud developer working with Azure, make sure to familiarize yourself with Azure RBAC because you use it with just about any resource that has security concerns.
Add cross-cutting concerns
- Manage your application secrets using Azure Key Vault
- Gain visibility into your app by logging with Azure Monitor
Host your Python app
If you want your app code to run on Azure, you have several options as described in Hosting applications on Azure.
If you're building web apps or APIs (Django, Flask, FastAPI, and so on), consider:
- Azure App Service
- Azure App Service (already containerized)
- Azure Container Apps
- Azure Kubernetes cluster
If you're building a web application, see Configure your local environment for deploying Python web apps on Azure.
Also, if you're building a web API, you should consider using Azure API Management.
If you're building back-end processes: