I have a python Funktion function_app.py
(triggered every minute) in Azure Like this
import azure.functions as func
import logging
app = func.FunctionApp()
@app.timer_trigger(schedule="0 */1 * * * *", arg_name="myTimer", run_on_startup=False,
use_monitor=False)
def zsdbi(myTimer: func.TimerRequest) -> None:
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('09 Python timer trigger function executed.')
On the same Level in the Filesystem I have a file newconfig.py
like this :
class MyConfig:
def __init__(self, ftp_host=None, ftp_username=None, ftp_password=None,
sharepoint_url=None, sharepoint_clientid=None, sharepoint_clientsecret=None, azure=False):
self._ftp_host = ftp_host
self._ftp_username = ftp_username
self._ftp_password = ftp_password
self._sharepoint_url = sharepoint_url
self._sharepoint_clientid = sharepoint_clientid
self._sharepoint_clientsecret = sharepoint_clientsecret
When I try to import newconfig.py
in function_app.py
like this :
import azure.functions as func
import datetime
import json
import logging
import newconfig # This results in Error
app = func.FunctionApp()
@app.timer_trigger(schedule="0 */1 * * * *", arg_name="myTimer", run_on_startup=False,
use_monitor=False)
The function is not running anymore I assume caused by an error during Import. How can I add additonal python files not available in public packages to my Azure function
Edit 1
The function is deployed via github actions as :
steps:
- name: Checkout
uses: actions/checkout@v4
- name: 'Azure Login'
uses: azure/login@v2
with:
client-id: ${{ env.ARM_CLIENT_ID }}
subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }}
tenant-id: ${{ env.ARM_TENANT_ID }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: 'Download Azure Function publishing profile'
env:
AZURE_SUBSCRIPTION_ID: ${{ env.ARM_SUBSCRIPTION_ID }}
FUNCTION_APP_RESOURCE_GROUP: ${{ env.ARM_RESOURCE_GROUP_NAME }}
FUNCTION_APP_NAME: fa-${{ env.APP_NAME }}
run: |
echo "FUNCTION_APP_PUB_PROFILE=$(az functionapp deployment list-publishing-profiles --subscription $AZURE_SUBSCRIPTION_ID --resource-group $FUNCTION_APP_RESOURCE_GROUP --name $FUNCTION_APP_NAME --xml)" >> $GITHUB_ENV
- name: "Deploy function"
uses: Azure/functions-action@v1
with:
app-name: fa-${{ env.APP_NAME }}
publish-profile: ${{ env.FUNCTION_APP_PUB_PROFILE }}
package: src
src
containing all python files
Add newconfig.py
in the same directory as your function_app.py
.
If newconfig.py
is located in a subfolder, you will need to adjust the import path accordingly.
Example: If newconfig.py
is placed in a subfolder named config
, you'll need to import it like this:
from config import newconfig
I have created a Python function with the folder structure as below:
Folder Structure:
| .gitignore
| function_app.py
| host.json
| local.settings.json
| newconfig.py
| requirements.txt
|
+---.vscode
+---__blobstorage__
+---__pycache__
\---__queuestorage__
function_app.py:
import azure.functions as func
import datetime
import json
import logging
import newconfig
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:
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function executed.')
Console Output:
C:\Users\uname\pyfn>func start
Found Python version 3.11.9 (py).
Azure Functions Core Tools
Core Tools Version: 4.0.6280 Commit hash: N/A +421f0144b42047aa289ce691dc6db4fc8b6143e6 (64-bit)
Function Runtime Version: 4.834.3.22875
[2025-01-16T04:56:45.691Z] Worker process started and initialized.
Functions:
timer_trigger: timerTrigger
For detailed output, run func with --verbose flag.
[2025-01-16T04:56:50.481Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2025-01-16T05:00:00.177Z] Executing 'Functions.timer_trigger' (Reason='Timer fired at 2025-01-16T10:30:00.0790914+05:30', Id=82facfd3-7236-4eab-a83f-339a45475c96)
[2025-01-16T05:00:00.337Z] Python timer trigger function executed.
[2025-01-16T05:00:00.389Z] Executed 'Functions.timer_trigger' (Succeeded, Id=82facfd3-7236-4eab-a83f-339a45475c96, Duration=280ms)