In this Azure tutorial, we will discuss Azure functions Python Example including the steps to Deploy Python Azure Function To Azure From Visual Studio Code and Create Python Azure Function In Azure Portal.
Subscribe to Our YouTube Channel for more videos
Table of Contents
How To Create Azure Function In Python
Well, like we are creating the Azure Function using C#, JavaScript, etc. In the same way, you can also create an Azure Function using Python.
Prerequisites
Before starting the development, we should know what is needed to create Azure function in Python.
- Make sure to install the Visual Studio Code along with Azure Functions Extensions if you have not yet installed the Visual Studio Code. Install the Visual Studio Code now.
- The next thing you need is Python 3.7.x or 3.6.x or 3.8.x etc
- An Azure Free Account or Azure Subscription.
Now, Assuming we are ready with all the Prerequisites, Let’s start the actual development of the Python Azure Function.
To Create Azure Function In Python, follow the below steps
1. Open the Visual Studio Code, click on the Azure Button from the left side, and then click on the Create New Project button in the Functions Explorer as highlighted below.

2. Now is the time to choose the location to save your Azure Function project. You can click on the Browse button to navigate to the local path where you want to save your Azure Function project.

3. This step is very important. Select the language Python to create the Azure Function Project.

4. You need to select the Python interpreter. Make sure to select the correct version. Specify the location of your Python 3.6.x executable. Again, make sure you’re using a compatible version of Python.

5. The next step is to choose the trigger that will invoke your Azure Function, and it is very important to select the required trigger based on your requirements. Let’s select the Basic and simplest trigger option, the HTTP trigger.

6. Now, the next step is you need to provide a unique name for your Azure Function, like the one below

7. The next step is to choose the Authorization level for your Azure Function. Choose the Authorization level as Function here. You can choose any of the options based on your requirements.

8. Select the Open in the new window, or you can choose the Open in the current window based on your choice.

If you are trying to create the Azure Function in Python for the first time then it might ask you to install the below-recommended extensions, you can click on the install button as highlighted below.

Suppose you have not installed Python by now. In that case, It might prompt you to install Python, Click on the Open button as highlighted below, which will redirect to Python’s official website to download Python 3.6 or the latest version for your operating system.

You can download the Python 3.6.x version for the operating system that you are using and install the same on your machine.
Now you can see the Azure Function Project is already created using Python and is ready to use. You can see the _init._.py class file was created with the below piece of code
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
Now, it might show you the Below Pop saying, “Linter pylint is not installed.” So click on the Install button to install the Linter pylint.

Test Python Azure Function Locally
Now, we will run and check if the Azure Function is working fine or not. Press F5 to run the Azure Function or click on the Run button from the Visual Studio Code.
You can see below we got the Azure Python Function URL
The URL looks like below
http://localhost:7071/api/MyNewPythonfunction

Now open your Favorite Browser and Paste the Function URL, Now you can able to see below, it is asking us to Provide the name value parameter in the query string.

Now, I am appending the ?name=raj with the Azure Function URL. You can see we got the expected output below.

This is the way to create the Python Azure function in Visual Studio code. So, our Python Azure Function is working as expected without any issues. Now it’s time to deploy your Python Azure Function to Azure.
Deploy Python Azure Function To Azure From Visual Studio Code
Follow the below steps to deploy the Python Azure Function to Azure
Now click on the Azure button again and then click on the Deploy to Function App button, as highlighted below.

Now click on the + Create new Function App in Azure button.

The next step is to provide a unique name for the function app and click on Enter.

Select the runtime stack version from the below window

Next, you need to select the region for the new resource, and Now it will start deploying the Azure Python Function to the Azure Portal.

This way will help you write Azure Functions In Python and Deploy your Azure Function In Python.
How To Create Python Azure Function In Azure Portal
Follow the below steps.
- Log in to the Azure Portal (https://portal.azure.com/)
- Search for the Function App in the Azure Portal and click on the search result

3. On the Azure Function App page, click on the + Add button to create a new Azure Function App.
The next step is, On the Create Function App Page, Provide the below Details
- Subscription: Choose the Correct Azure Subscription that you want to use here.
- Resource Group: You can choose your existing Resource Group, or if you don’t have an existing Resource Group, you can create a new one by clicking on the Create new link.
- Function App name: You must provide a unique name for your Azure Function App.
- Publish: Choose the Code option here.
- Runtime Stack: Make sure to choose the Python option here.
- Version: Choose the latest version of Python here.
- Region: You need to choose the Region for your Azure Resource.
Now, after providing all the above details, click the Review + Create button.

Check out How To Find Azure Functions Run Time Version
For your information, If you navigate to the Hosting Tab once, you can see that Linux is the only operating system supported now when you are choosing the Runtime stack as Python.

Now it will validate all the details provided by you, Finally, click on the Create button on the next screen to create the Azure Function App.
Now, You can see the Azure Function App is deployed successfully. Click the Go to Resource button to navigate the Azure Function App.

So Our Azure Function App is ready now, the next thing we need is to create the Azure Function. On the Function App page, click on the Functions from the left navigation and then click the + Add button to create the Azure Function.

Check out How to use dependency injection in Azure Functions
On the Add function window, choose the Development environment as Develop in the portal, Select the template as HTTP trigger, Provide a name for the new function and Authorization level as Function, and finally, click on the Add button to create the new function.

Now you can see the Azure Python Function created successfully

This is the way to write Python Azure Function In Azure Portal
You may also like following the below Articles
- How To Call A Stored Procedure From Azure Functions
- Where To Instantiate Database Connection In Azure Functions
Wrapping Up
In this article, we discussed Azure Function Python Example, Azure Functions In Python, and Deploy Python Azure Function To Azure From Visual Studio Code, Create Python Azure Function In Azure Portal. I hope you have enjoyed this Article !!!

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
