Decorators - Building an API in Python with Flask
Tags: python, webdev, beginners, twitch
Published: 2020-01-29 21:35:05

---
title: Decorators - Building an API in Python with Flask
published: true
description: Live stream recap notes from Twitch with Cecil Phillip and Brian Clark on January 29, 2020
tags: python,webdev,beginners,twitch
cover_image: https://user-images.githubusercontent.com/6265396/73398950-5e306d80-42b4-11ea-9698-6b61d4c3e336.png
canonical_url: https://www.clarkio.com/stream/python/2020-01-29
---

In this session, Brian and chat learn about decorators with Flask as they build out an API in Python. They started off by getting stuck on an issue with recreating the same environment from past sessions but work through it and fix the install script. They finish up by successfully implementing a decorator that checks if the request to the API has been authenticated.

The following are notes and details recapping a past live stream where we live code together. The idea behind these streams is that they provide real-world examples of running into problems and solving them or working towards solving them live. Enjoy this latest one on Python 🙂👍

# Wednesday - January 29, 2019

- [Twitch](https://www.twitch.tv/videos/543661356?t=00h04m15s)
- [YouTube](https://youtu.be/o3Qc-wQX_Zw)

## Goals

- ✔ Warm up/Catch up with chat
- ✔ Learn about Decorators in Python
- ✔ Closing and raid [@GarethHubball](https://twitch.tv/GarethHubball)

## Results

- Fixed an issue with the environment installation script to make sure our project can be setup and run easily
- Learned about decorators
- Learned about the build in Session class available in Flask
- Created our own decorator to protect an API endpoint

## Resources

- [Project Repo](https://github.com/cecilphillip/python-flask-stream)
- [Visual Studio Online Configuration](https://docs.microsoft.com/en-us/visualstudio/online/reference/configuring?WT.mc_id=devto-blog-cxa)
- [VS Code Containers Documentation](https://github.com/microsoft/vscode-dev-containers/?WT.mc_id=devto-blog-cxa)
- [GitHub CLI Tool](https://github.com/github/hub)
- [Flask](https://palletsprojects.com/p/flask/)
- [Python Cheat Sheet](https://www.pythoncheatsheet.org/)
- [Microsoft Developer's Python for Beginners](https://www.youtube.com/watch?v=jFCNu1-Xdsw&list=PLlrxD0HtieHhS8VzuMCfQD4uJ9yne1mE6)

## VS Code Extensions Shown/Used

- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python&WT.mc_id=devto-blog-cxa)
- [VS Live Share](https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare-pack&WT.mc_id=devto-blog-cxa)
- [Visual Studio Online VS Code Extension](https://marketplace.visualstudio.com/items?itemName=ms-vsonline.vsonline&WT.mc_id=devto-blog-cxa)

## Clips

Clips are a feature on Twitch that let you cut and capture segments of the live stream in the moment (up to 60 seconds). See [how to use clips on Twitch](https://help.twitch.tv/s/article/how-to-use-clips) for more details. The following are some fun moments captured from this stream:

- N/A

## Segments

> Links not working on Twitch? It's most likely because Twitch will only save my stream recordings for about 60 days. Use the YouTube link at the top of this page instead.

This table helps point out different segments of the stream (highlighted in bold) or moments we learned something (not bold). The timestamps link to the video on Twitch at that point in the recording. If you'd like the YouTube link above will have similar timestamps and link to those same points in the recording as well.

| Timestamp                | Topic       |
| ------------------------ | ----------- |
| [00:04:15](https://www.twitch.tv/videos/543661356?t=00h04m15s) | **Stream is back and we're moving into the Python stuffs**                                               |
| [00:07:05](https://www.twitch.tv/videos/543661356?t=00h07m05s) | **Reading/learning about view decorators in Flask**                                                      |
| [00:08:38](https://www.twitch.tv/videos/543661356?t=00h08m38s) | **View Decorators (created by [@murgmasallam](https://twitch.tv/murgmasallam))**                         |
| [00:12:09](https://www.twitch.tv/videos/543661356?t=00h12m09s) | **Authentication vs. authorization discussion**                                                          |
| [00:19:50](https://www.twitch.tv/videos/543661356?t=00h19m50s) | **Environment setup (created by [@GarethHubball](https://twitch.tv/GarethHubball))**                     |
| [00:40:25](https://www.twitch.tv/videos/543661356?t=00h40m25s) | **Looking at decorators (created by [@GarethHubball](https://twitch.tv/GarethHubball))**                 |
| [00:45:31](https://www.twitch.tv/videos/543661356?t=00h45m31s) | **Debugging the container (created by [@GarethHubball](https://twitch.tv/GarethHubball))**               |
| [01:37:23](https://www.twitch.tv/videos/543661356?t=01h37m23s) | **Finish fixing the environment and now moving on to the login decorator again**                         |
| [03:23:28](https://www.twitch.tv/videos/543661356?t=03h23m28s) | **Checking in changes by forking repo (created by [@codesillystuff](https://twitch.tv/codesillystuff))** |
| [03:28:45](https://www.twitch.tv/videos/543661356?t=03h28m45s) | **Closing and raid**                                                                                     |


## YouTube Video

{% youtube o3Qc-wQX_Zw %}

## Get connected with Cecil Phillip

- [Twitter](https://twitter.com/cecilphillip)
- [Twitch](https://twitch.tv/cecilphillip)
- [Instagram](https://instagram.com/cecilphillip)
- [GitHub](https://github.com/cecilphillip)
- [Website](https://cecilphillip.com/)

## Get connected with Brian Clark

- [Twitter](https://twitter.com/_clarkio)
- [Twitch](https://twitch.tv/clarkio)
- [Instagram](https://instagram.com/_clarkio)
- [YouTube](https://youtube.com/clarkio)
- [GitHub](https://github.com/clarkio)
- [Website](https://www.clarkio.com)

-----

Thanks for reading this article. If you're interested in finding more content from Microsoft Cloud Advocates check out this monthly curated newsletter: [Developer Community Newsletter](https://azure.microsoft.com/en-us/resources/join-the-azure-developer-community/?WT.mc_id=pythonfromscratch-devto-cxa)