Azure Functions is a serverless computing service that enables developers to deploy small pieces of code without the need to manage the underlying infrastructure. It supports various programming languages, including .NET, Python, JavaScript, TypeScript, Java, PowerShell, and C#, providing flexibility and versatility for various applications. This article describes how to create Python Azure function in Visual Studio code.

Prerequisites:
1. Visual Studio Code installed on your machine.
2. Azure Functions Core Tools installed. This can be installed via Node.js or the npm install -g azure-functions-core-tools@4 --unsafe-perm true command.
3. Python Interpreter (Ensure Python 3.8 or later is installed, preferably the latest version). Install it from Microsoft Store.
4. Azure Account with an active subscription. If you don’t have one, create a free Azure account at Azure Free Account.
5. Azure Functions Extension for Visual Studio Code installed. Install this from the Extensions marketplace in Visual Studio Code.
6. Azure CLI (Command Line Interface), for deploying the function.

create python azure function

Follow the below steps to Create Python Azure function in Visual Studio Code

1. Open Visual Studio Code and on the left-hand side ribbon, Click Azure Icon. A menu at the bottom will pop up. Click on the Azure function icon and click the ‘Create Function’ menu item.

2. Select Python as a language as shown in the below image.

3. Select ‘Model V2’ as the Python programming model.

4. Select a supported Python version. For new projects, use the latest generally available Python version supported by your Azure Functions hosting plan. At the time of writing, Python 3.14 is GA.

5. Select the type of trigger you want to use for this function. In our case, we will use the Time trigger. Provide a CRON Expression (e.g., 0 */5 * * * * for every 5 minutes) to schedule the timer trigger.

create python azure function

6. Once the above steps are complete, Visual Studio Code will generate a Python Azure Function project using the V2 programming model. Unlike the older V1 model, there’s no function.json or __init__.py — everything lives in a single function_app.py file, with the trigger defined as a decorator. Open function_app.py and add your logic as shown below.

Understanding the Generated Project Structure

After completing the wizard, VS Code scaffolds a V2 Python Functions project with the following files:

  • function_app.py — the main file where your function logic and trigger decorators live. This is what you’ll edit to add your code (shown below).
  • host.json — configuration for the Functions host itself (logging levels, extension bundle version, timeout settings). You typically won’t need to touch this for a basic function.
  • local.settings.json — local-only environment variables and connection strings (like AzureWebJobsStorage and FUNCTIONS_WORKER_RUNTIME). This file is not deployed to Azure — see the Azurite setup below for why AzureWebJobsStorage matters.
  • requirements.txt — your Python package dependencies. The azure-functions package is added by default; add any other libraries your function needs here, then run pip install -r requirements.txt in the project’s virtual environment.
  • .venv/ — the Python virtual environment VS Code created for you when you selected an interpreter in step 4. Make sure VS Code has this selected as the active interpreter (check the bottom-right of the status bar).

Now open function_app.py and add your function logic:

import azure.functions as func
import datetime
import logging

app = func.FunctionApp()

@app.timer_trigger(schedule="0 */5 * * * *", arg_name="myTimer", run_on_startup=False, use_monitor=False)
def timer_trigger(myTimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()

    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

Setting Up Local Storage for the Timer Trigger

Timer, Blob, and Queue triggers all depend on Azure Storage to keep track of trigger state — even when running locally. Before you can debug with F5, you need a storage connection configured in local.settings.json. You have two options:

Option A — Use Azurite (recommended for local development)

  1. Install the Azurite extension in VS Code (search “Azurite” in the Extensions marketplace), or install it globally via npm install -g azurite.
  2. Start Azurite: open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and run Azurite: Start, or run azurite in a terminal.
  3. Open local.settings.json in your project and confirm AzureWebJobsStorage is set to "UseDevelopmentStorage=true":
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python"
  }
}

Option B — Use a real Azure Storage account

Replace the AzureWebJobsStorage value with the connection string from an actual Storage Account in Azure (Portal → Storage Account → Access Keys). Useful if you want local runs to write to real storage, but it does incur minor costs and requires network access.

Debugging Your Function Locally

Once Azurite is running (or a real connection string is set), you’re ready to debug locally.

  1. Make sure Azurite is running (see above) before you start debugging.
  2. Press F5 or click on the Run and Debug option in Visual Studio Code.
  3. Azure Core Tools will emulate the function runtime locally, allowing you to test the functionality.

Deploying the Function to Azure

  1. Click on the Azure Icon in Visual Studio Code.
  2. Sign in to your Azure account if not already done.
  3. Right-click on the Functions node and select Deploy to Function App.
  4. Follow the prompts to create or choose an Azure Function App in your subscription.

We have seen how to create Python Azure function in Visual Studio Code.

See more

Kunal Rathi

With over 15 years of experience in data engineering and analytics, I've assisted countless clients in gaining valuable insights from their data. As a dedicated supporter of Data, Cloud and DevOps, I'm excited to connect with individuals who share my passion for this field. If my work resonates with you, we can talk and collaborate.