Generate a PowerPoint file using Azure Functions and Python
Tags: python, azure, cloud, serverless
Published: 2021-08-24 02:41:17

---
title: Generate a PowerPoint file using Azure Functions and Python
published: true
date: 2021-07-26 23:30:00 UTC
tags: Python,Azure,Cloud,Serverless
canonical_url: https://blog.siliconvalve.com/2021/07/27/generate-a-powerpoint-file-using-azure-functions-and-python/
---

For many years I have been involved with the [Azure Sydney User Group](https://www.meetup.com/Azure-Sydney-User-Group/), and even though I’m no longer the organiser I still gather updates for Azure in the prior month and prepare a PowerPoint presentation that contains them. My go-to place for the information is the [Azure Updates website](https://azure.microsoft.com/updates/) and I’ve typically just been browsing the site and manually updating an existing PowerPoint template.

Recently I reflected on the amount of time it takes for me to click through the pages and pull out the headlines, and decided this probably wasn’t a great use of my time. Even though it’s typically under 10 minutes to do it’s still repetitive which clearly means it’s the perfect candidate to automate!

I’ve used it for other integration in the past, so I know the updates website has an RSS feed which is perfect for automation.

## Choosing an implementation approach

There are a few ways I could have built an automation, and my original intention was to use either Azure Logic Apps or Power Automate Flow and integrate into PowerPoint online in Microsoft 365. Unfortunately, it turns out there is no native PowerPoint online connector which means this approach became a no-go!

In the absence of this integration capability, I decided to turn to a code-based solution because I know there are many ways to generate Office documents through SDKs that implement the Office Open XML File Formats standard ([ECMA-376](https://www.ecma-international.org/publications-and-standards/standards/ecma-376/)).

One of the reasons I also looked at Logic Apps or Power Automate was their serverless pay-on-execution model. Keeping this in mind I turned to my trusty friend, Azure Functions. At this stage the no-brainer for me as a long-term C# developer would have been to implement a .NET-based Function, but as I’ve said a few times before, I’m wanting to push my skills to cover other languages, so I thought I’d have a go with Python.

## Azure Functions + Python = ❤

It turns out there is an excellent PowerPoint library called [python-pptx](https://python-pptx.readthedocs.io/en/latest/) that has everything I needed, and I found an great [blog and sample from Matthew Wimberly](https://codeburst.io/building-an-rss-feed-scraper-with-python-73715ca06e1f) that had what I needed to read and parse an RSS feed. Now I had these two elements I needed a little bit of Functions magic to tie it together and provide a simple HTTP API I could use to generate my presentation.

The resulting Azure Function (shown below) does all I need in less than 200 lines of code.

{% gist https://gist.github.com/sjwaight/f7ce5a24ea6e59978186e8d07e9f4853 %}

To run it, you invoke the Function via a web browser with a URL similar to:

```
https://your-func-app.azurewebsites.net/api/GeneratePresentation?code=YOUR-FUNC-KEY&start=2021-06-20&end=2021-06-30
```

If the supplied date range is valid and there are updates that fall within it, you receive a simple web page with a link to a downloadable PowerPoint file held in a private Azure Storage account which is served for a limited period using a SAS-protected URL. The full documentation around how to debug, deploy and execute the Azure Function can be be found on the [GitHub repository for the solution](https://github.com/sjwaight/AzureUpdatesPresentationGen). Also, here’s a [sample of what you can generate](https://siliconvalve.files.wordpress.com/2021/07/azureupdate-2021-07-23-01-43-09.pptx).

I have deployed the solution onto a Consumption plan in Azure which means I’m not paying for idle compute, and the PowerPoint takes up so little space that my Storage Account costs will be tiny, especially given this API endpoint can’t be invoked by just anyone. Finally, to save myself even more money, I have a Timer Function that once a week deletes any PowerPoint files sitting in the Storage Account, which won’t be many (if any) for most of the time.

I’m pretty happy with the solution as it stands, but in future I might look to use my existing PowerPoint template as the base for the resulting presentation which means there would be even less manual work for me to do. Right now I still need to copy / paste from one PowerPoint to the other, but this is so trivial that I’m not bothered about automating it away … just yet 😉.

Hopefully you find some inspiration in the solution here!

Happy Days! 😎

P.S. The GitHub repository with the solution is here: [https://github.com/sjwaight/AzureUpdatesPresentationGen](https://github.com/sjwaight/AzureUpdatesPresentationGen)