
In this Azure tutorial, we will discuss How To Create Azure Functions In Python. Along with this, we will also discuss a few other topics like Azure Functions In Python and we will also discuss Deploy Python Azure Function To Azure From Visual Studio Code, and Create Python Azure Function In Azure Portal.
How To Create Azure Functions In Python? You can able to create these Azure Functions in Python using the Visual Studio Code IDE.
- Create a Python Azure Function Project using Visual Studio Code.
- Choose the Project location and Python as the language.
- Select Python Interpreter.
- Choose the trigger that will invoke your Python Azure Function.
- Provide a name for your Python Azure Function and choose the Authorization level based on your requirement.
- Select the runtime stack and the region for your resource. Below we will discuss this in detail.
Subscribe to Our YouTube Channel for more videos
Table of Contents
How To Create Azure Functions In Python
Well, here we will discuss How to create Azure Function in Python. Before moving to the actual topic, we will discuss a bit about what is Azure Function.
What is Azure Function?
Azure Functions is simply a “Functions-as-a-service” that provides the solution to run a few lines of code that are termed as functions in the cloud environment. You just need to worry about writing the code. No need to take any headache for the whole application or the infrastructure. You can find out more information on Azure Function now.
Azure Functions In Python
Well, like we are creating the Azure Function using C#, JavaScript, etc. In the same way, you can able to create an Azure Function using Python as well.
Prerequisites
Before starting the actual development, we should know what is the stuff needed to Develop Azure Functions 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 Azure Function using Python.
Open the Visual Studio Code and 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.

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.

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

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.

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 requirement. Let’s select the Basic and simplest trigger option which is the HTTP trigger here.

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

Now 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 requirement.

Select the Open in new window or you can choose the Open in 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.

If you have not installed Python by now, 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 able to see the Azure Function Project is already created using Python and is ready to use. You can able to see the _init._.py class file got 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 up 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 able to 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 able to see we got the expected output below

This is the way to create 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

The next is, 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

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 need to 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 you provide all the above details, then click on the Review + Create button.

For your information, If you will navigate to the Hosting Tab once, you can able to see that Linux is the only operating system that is supported as of 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 able to see the Azure Function App is deployed successfully. Click on the Go to Resource button to navigate to 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 on the + Add button to create the Azure Function.

On the Add function window, choose the Development environment as Develop in portal, Select the template as HTTP trigger, and then Provide a name for the new function and Authorization level as Function and then finally click on the Add button to create the new function.

Now you can able to see the Azure Python Function created successfully

This is the way for writing 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
Well, In this article, we discussed Azure Functions In Python, How To Create Azure Functions In Python and we also discussed Deploy Python Azure Function To Azure From Visual Studio Code, Create Python Azure Function In Azure Portal. Hope you have enjoyed this Article !!!