Python File with Azure Functions

Viewed 118

Ive written a python script to get information from an API, do some Pandas wrangling and format it to insert into my azure postgres instance with SQLAlchemy. I'd like to be able to run this every night, obviously automated, but I can't find anything that actual shows details about how to incorporate azure functions or how to incorporate my script into azure functions.

Any help would be great, but I'd really appreciate resources that you have found helpful.

1 Answers

The easiest way would be by the usage of Time trigger, then use Cron format to specify the desired time for the execution.

Here's a sample:

function.json

{
    "name": "mytimer",
    "type": "timerTrigger",
    "direction": "in",
    "schedule": "0 */5 * * * *"
}

code:

import datetime
import logging

import azure.functions as func


def main(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)

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python#example

Related