Advent 2021: Flask
This blog is part of the 24 posts long series "Advent 2021":
- Advent 2021: Intro (December 01, 2021)
- Advent 2021: C++ (December 02, 2021)
- Advent 2021: C# (December 03, 2021)
- Advent 2021: Python (December 04, 2021)
- Advent 2021: Go (December 05, 2021)
- Advent 2021: TypeScript (December 06, 2021)
- Advent 2021: CMake (December 07, 2021)
- Advent 2021: Django (December 08, 2021)
- Advent 2021: Angular (December 09, 2021)
- Advent 2021: Flask (December 10, 2021)
- Advent 2021: gRPC (December 11, 2021)
- Advent 2021: GraphQL (December 12, 2021)
- Advent 2021: XML & JSON (December 13, 2021)
- Advent 2021: Matplotlib, Pandas & Numpy (December 14, 2021)
- Advent 2021: Linux (December 15, 2021)
- Advent 2021: Ansible (December 16, 2021)
- Advent 2021: SQLite (December 17, 2021)
- Advent 2021: Catch2 (December 18, 2021)
- Advent 2021: Zstandard (December 19, 2021)
- Advent 2021: ZFS (December 20, 2021)
- Advent 2021: Thunderbird (December 21, 2021)
- Advent 2021: Visual Studio Code (December 22, 2021)
- Advent 2021: Blender (December 23, 2021)
- Advent 2021: Open source (December 24, 2021)
Having talked about my favorite combination of web frameworks – Angular for the frontend and Django there’s still one more thing I want to cover on the web framework side: Flask. For “serious” web development, Django has been my default choice, but I did end up with several Flask applications. In some cases, I already had a database layer written in SQLAlchemy, so porting that to Django would have only taken time and using Flask meant I could use it with no changes.
Flask is a “micro” framework and excels in those “I really need to get something running right now” cases, more so if you’re working with others who may not be familiar with Django, as Flask literally allows you to get up to speed with a single file. It also comes with very extensive documentation that covers plenty of “real-world” problems that you might run into.
In my experience, Flask also excels at being highly modular yet never feeling like a set of disjoint pieces. I had one case where I started with Flask and had to grow the application relatively quickly by adding a proper ORM, integrate with a task queue, and replace the HTML templates with a REST interface that was driven from an Angular SPA. Even though that resulted in significant changes to the application, I never ran into issues with not being able to make a change because components would stop working or something. This ability to scale is welcome if you’re just starting out and you don’t know very well where you’re going. The REST API in particular was interesting – I had to change all page templates to produce JSON, and this was something that I did right within Flask. If you’re occasionally writing some web tool, and you want to get something up and running within an hour, do give Flask a try!