Running Python Flask apps on Azure App Service

I enjoyed speaking at the Sydney Python (SyPy) meetup on how Python Flask developers can quickly deploy their web applications onto Web Apps hosted on Linux on the Azure App Service platform.

But… why Python?!

Anyone taking a cursory glance through my writings will see that prior to last year I didn’t write about Python. It’s not that I wasn’t interested, it’s just that I wasn’t spending any time working with the language. Throughout my career I’ve had the chance to work with all sorts of languages and I have to say that Python’s been one on my list to use for a while. Clearly a lot of people love it and are making good careers out of it!

The role I currently have has given me more time to invest in learning new languages and you can see that I’ve started blogging more about Python, though I am clearly closer to a noob than an advanced user! My nirvana moment came when I realised that the Try Except construct looked very familiar to C#’s (but don’t talk to me about tabs / spaces or colons…)

In future I’ll be writing a bunch more about Python in the context of Azure Functions because I think serverless has a lot to offer the data science and machine learning communities – both of which are heavy users of Python.

Free Continuous Deployment (CD)

For this session I used App Service’s inbuilt CD offering, Kudu, which can use webhook triggers on Github, Git and Bitbucket repositories as a mechanism to trigger a deployment. Kudu is open source so you can check out how it works on GitHub.

Kudu uses a pull-based CD approach where it will clone your repository locally and than do work based on the contents it finds (such as recognising a repository contains Python code, for example). Kudu is really handy when you don’t have an existing CD process and want to rapidly configure hands-free deployments.

If you want to perform push-based CD, then you can use services like Azure DevOps, Bitbucket Pipelines or GitHub Actions to push your solution. I looked at using GitHub Actions in a previous blog post.

As a value add for those reading this far… the App Service team is also adding a new build engine along the lines of Kudu (which is named after an African antelope) called Oryx (also named after an African antelope) which is also open source and on GitHub.

Runtime Configuration

I glossed over this in the talk, but a powerful feature of App Services is Application Settings. These hold runtime configuration values, and in the Python world are passed into your running application as environment variables that are accessible using the familiar ‘os.environ’ array. You can publish these via the CLI or edit them directly in the Portal.

Presentation

My slides from this talk are below.

Useful Links

Rather than dump a bunch of links into the back of my slides I thought I would bring them here and give a bit more context to each.

Feel free to reach out on Twitter @simonwaight or drop me an email (I bet you can figure it out @microsoft.com).

Happy Days 😎

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s