Azure Function Apps with Python

Azure Function Apps allows to develop server-less application on Azure platform. For those of you who are wondering what exactly are those, think of something like a platform to run your code on cloud without setting up Cloud VMs(Server), which are pretty expensive when you only need to run something simple such as a single Python Script. It’s an inexpensive way of running your Scripts. If you wanna read more about it, go here.

At the time of writing the post, Function Apps supports languages such as C#, F#, Node.js, Python, or PHP. And in coming days you might see a lot more support for other languages.

Running Python scripts are my prime concern but Python support is still in beta stage. But there are some workarounds by which you can set up the environment as you desire.

By default it comes with Python 2.7.x but since the whole community is slowly shifting towards Python 3.X. First challenge is to get the environment to Python 3.6.x which is latest.

Note : If you don’t have an account yet, you can just sign up for a free-trial and Azure will give you free credits for a month to test their services.

You can follow the steps under :

1.Create an Function App by going to the Azure Portal then NewComputeFunction AppEnter Details & Select SubscriptionCreate

2. After your Function App is allocated go to Functions Tab → +Custom Function link → Choose Language “Python” → Select Type of ApplicationGive a NameCreate

You can check the platform by typing two lines of code below:

import platform
print("Python == ", platform.python_version())

In the logs Tab you will find Python == 2.7.x.

3.Get Python 3.x environment

D:\home\site\tools> nuget.exe install -Source https://www.siteextensions.net/api/v2/ -OutputDirectory D:\home\site\tools python361x64
  • We need the python.exe (Python 3.6.x) in D:\home\site\tools, use the following command
D:\home\site\tools> mv /d/home/site/tools/python361x64.3.6.1.3/content/python361x64/* /d/home/site/tools/
  • Now install custom packages using pip
D:\home\site\tools> python.exe -m pip install requests

You can install all the required packages for your environment and then run code with ease. There are a lot more features in Function Apps, make sure to check them out and use if it meets your use case without the hassle and cost of maintaining a dedicated VM.