Azure Functions Python Development on Mac¶
- Uses Visual Studio Code
Prerequisites¶
Before setting up Azure Functions development on Mac, ensure you have the following installed:
1. Homebrew¶
Homebrew is the package manager for macOS that we'll use to install dependencies.
For more information: Homebrew
2. Miniconda or Anaconda¶
Azure Functions supports Python 3.8, 3.9, 3.10, and 3.11. We'll use conda to manage Python environments.
Install Miniconda (lightweight) using Homebrew:
Or install Anaconda (full distribution):
After installation, initialize conda for your shell:
Restart your terminal, then verify installation:
For more information: Miniconda | Anaconda
3. Visual Studio Code¶
Download and install Visual Studio Code:
Or download directly from: Visual Studio Code
4. Azure CLI (Optional but Recommended)¶
The Azure CLI is useful for managing Azure resources:
Verify installation:
Login to Azure:
For more information: Install Azure CLI on macOS
Setup¶
Install Azure Functions Core Tools¶
Azure Functions Core Tools lets you develop and test your functions on your local computer.
Install using Homebrew:
If upgrading on a machine that already has Core Tools installed:
Verify installation:
For more information: Azure Functions Core Tools
Install Azure Functions Extension for Visual Studio Code¶
- Open Visual Studio Code
- Go to Extensions (⌘+Shift+X)
- Search for "Azure Functions"
- Install the extension published by Microsoft (
ms-azuretools.vscode-azurefunctions)
Or install via command line:
Install Python Extension for Visual Studio Code¶
The Python extension provides rich support for Python development:
- Open Visual Studio Code
- Go to Extensions (⌘+Shift+X)
- Search for "Python"
- Install the extension published by Microsoft (
ms-python.python)
Or install via command line:
Getting Started¶
Create a New Azure Functions Project¶
- Open VS Code and press
⌘+Shift+Pto open the command palette - Type and select
Azure Functions: Create New Project - Select a folder for your project
- Choose Python as the language
- Select your Python interpreter (from your conda environment)
-
Choose a template for your first function:
- HTTP trigger - responds to HTTP requests
- Timer trigger - runs on a schedule
- Blob trigger - processes blob storage events
- And more...
-
Provide a function name
- For HTTP trigger, select authorization level:
- Anonymous - no authentication required
- Function - requires a function key
- Admin - requires a master key
Project Structure¶
After creating a project, you'll see the following structure:
MyFunctionApp/
├── .venv/ # Virtual environment (if using venv)
├── .vscode/ # VS Code settings
│ ├── extensions.json
│ ├── launch.json
│ ├── settings.json
│ └── tasks.json
├── function_name/ # Your function folder
│ ├── __init__.py # Function code
│ └── function.json # Function configuration
├── .funcignore # Files to ignore when deploying
├── .gitignore
├── host.json # Global configuration
├── local.settings.json # Local environment variables
└── requirements.txt # Python dependencies
Run Functions Locally¶
-
Create and activate a conda environment:
-
Install dependencies:
-
Configure VS Code to use the conda environment:
- Press
⌘+Shift+Pand selectPython: Select Interpreter - Choose the conda environment you created (e.g.,
Python 3.11.x ('azurefunctions'))
- Press
-
Start the function app:
Or press
F5in VS Code to start debugging -
Test the function: The terminal will show the local URL (typically
http://localhost:7071/api/your-function-name)
Deploy to Azure¶
Using VS Code¶
- Press
⌘+Shift+Pand selectAzure Functions: Deploy to Function App - Select your subscription
- Choose to create a new Function App or select an existing one
-
Follow the prompts to configure:
- Globally unique name
- Runtime (Python 3.11)
- Region
- Operating system (Linux)
Using Azure CLI¶
# Create a resource group
az group create --name MyResourceGroup --location eastus
# Create a storage account
az storage account create --name mystorageaccount --resource-group MyResourceGroup --location eastus --sku Standard_LRS
# Create a function app
az functionapp create --resource-group MyResourceGroup --consumption-plan-location eastus \
--runtime python --runtime-version 3.11 --functions-version 4 \
--name MyFunctionApp --storage-account mystorageaccount --os-type Linux
# Deploy the code
func azure functionapp publish MyFunctionApp
Configure Application Settings¶
Local settings are stored in local.settings.json and are not deployed to Azure. To configure settings in Azure:
Using VS Code¶
- Open the Azure extension
- Find your Function App
- Right-click on "Application Settings"
- Select "Add New Setting"
Using Azure CLI¶
az functionapp config appsettings set --name MyFunctionApp --resource-group MyResourceGroup \
--settings "SETTING_NAME=value"
Best Practices¶
- Use conda environments to isolate dependencies and manage Python versions
- Keep secrets out of code - use Application Settings or Azure Key Vault
- Test locally before deploying
- Use logging -
logging.info()instead ofprint() - Handle errors gracefully with try-except blocks
- Set appropriate timeout values in
host.json - Monitor your functions using Application Insights
- Use managed identities for authentication when possible
Common Issues on Mac¶
Issue: Conda not found after installation¶
Solution: Initialize conda and restart terminal:
Issue: Permission denied when installing packages¶
Solution: Ensure you're in an activated conda environment:
Issue: func command not found¶
Solution: Restart terminal or add Homebrew to PATH:
Issue: Python version mismatch¶
Solution: Ensure your conda environment Python version matches Azure runtime:
# Check current environment version
conda activate azurefunctions
python --version
# Create a new environment with specific Python version if needed
conda create -n azurefunctions python=3.11
# Update function app settings if needed
az functionapp config set --name MyFunctionApp --resource-group MyResourceGroup \
--linux-fx-version "Python|3.11"
Issue: VS Code not detecting conda environment¶
Solution: Ensure conda is in your PATH and restart VS Code:
# Add conda to PATH (if using Miniconda installed via Homebrew)
echo 'export PATH="/opt/homebrew/Caskroom/miniconda/base/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
References¶
- Azure Functions Python Developer Guide
- Azure Functions Core Tools Reference
- VSCode Azure Functions Extension
- VSCode Azure Functions Wiki
- Install Azure CLI on macOS
- Azure Functions Triggers and Bindings
- Azure Functions Best Practices
- Azure Functions Pricing
- Homebrew
- Conda User Guide
- Managing Conda Environments