Hi friends, recently I have been learning python for GenAI applications development and I thought of sharing some of the information related to Python with SharePoint. This article walks through creating a Python-based Azure Function that connects to SharePoint Online using Microsoft Graph API. It includes best practices, app registration, secure settings, virtual environment setup, local testing, and deployment instructions.
The above code is a sample which authenticates to SharePoint online using the Azure App and reads the list items from the given list. The settings are maintained in the local.settings.json. You will get some of the settings value from the next step on Azure App Registration
🔐 Step 4: Register App in Azure AD for Microsoft Graph
Azure Active Directory → App Registrations → New Registration
Name: SharePointGraphReader
Redirect URI: http://localhost
Save Application (client) ID, Directory (tenant) ID
API Permissions
Microsoft Graph
Delegated: Sites.Read.All, Sites.ReadWrite.All
Click “Grant Admin Consent” after adding.
Certificates & Secrets
Create a new Client Secret → Copy the value securely.
🧪 Step 5: Test Azure Function Locally
Ensure the virtual environment is active:
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
Run:
func start
Test via cURL
curl http://localhost:7071/api/GetSharePointData
You can test using the curl command or directly browse the URL in the browser which list down the list items based on the site url and lists you had configured in the local.settings.json file.
☁️ Step 6: Create Azure Function App for Python (Linux Required)
⚠️ Python is supported only on Linux-based Function Apps. Use the following:
# Login to Azure
az login
# Set variables
RESOURCE_GROUP="MyResourceGroup"
STORAGE_ACCOUNT="mystoragefunc123"
FUNCTION_APP="sharepoint-func-app"
LOCATION="eastus"
# Create resource group
az group create --name $RESOURCE_GROUP --location $LOCATION
# Create storage account (name must be globally unique)
az storage account create --name $STORAGE_ACCOUNT --location $LOCATION --resource-group $RESOURCE_GROUP --sku Standard_LRS
# Create function app on Linux (REQUIRED for Python)
az functionapp create \
--resource-group $RESOURCE_GROUP \
--consumption-plan-location $LOCATION \
--runtime python \
--runtime-version 3.9 \
--functions-version 4 \
--name $FUNCTION_APP \
--storage-account $STORAGE_ACCOUNT \
--os-type Linux
The above command will create the resource group, storage account and then will create the function app for deploying our function. You can also map your existing resource group and storage account and ran only the Create Function App command.
You can get the function key from Azure Portal → Function App → Functions → GetSharePointData → Get Function URL
Conclussion
I hope I was able to share some information about communicating to SharePoint via Python code and then to deploy as a Azure Function app. In future, lets see what are all the best practices that we can implement to make this func app more secure, robust and even work for large lists maintaining the consumption plan and much more.
Pingback: 🔐 Secure Python Azure Function Using Azure Key Vault and Managed Identity | Knowledge Share
Pingback: Improving Python Azure Function Performance: Handling Large SharePoint Lists with Throttling, Caching, and Batch Requests | Knowledge Share
Pingback: Robust Authentication with Microsoft Graph API (Using MSAL and Service Principals) | Knowledge Share
Pingback: 🚀 Building Resilient Azure Functions: Mastering Microsoft Graph API Calls with Python | Knowledge Share