Table of Contents
What is Flask?
Flask is a microframework for web development written in Python. It was created in 2004 by Armin Ronacher as an experiment that tried to bridge the lack of a WSGI implementation in the Python ecosystem. Curious about the single file module approach of Bottle, Armin bundled his creation into a similar format intending to play a joke. But the framework actually took off, and Armin learned that people appreciate and welcome frameworks that saved them the trouble of extensive configuration.
As the popularity of Flask took off, Armin found a way to balance his personal preferences for software configurations vs. the popular demand for a preconfigured system with little need for modifications. The result was Flask’s minimal approach to configuration. You can listen to this interesting origin story in Armin’s own words in this podcast on the RealPython website.
Flask and The Convention Over Configuration Debate
Convention over configuration is a design philosophy that minimizes the number of decisions a developer has to make when creating an application. Many software frameworks these days favor convention over configuration by providing sensible defaults that enable quick bootstrapping and shorter configuration files.
But the flip side to this approach is that a programmer unaware of the defaults could have a hard time tweaking the configuration. Seasoned programmers may also prefer to configure every little detail to their liking. In this case, the default configurations actually get in the way and become more of a hassle than a convenience.
Flask tries to balance the pros and cons of each philosophy but takes a less opinionated approach. It provides minimal configuration with sensible defaults and shifts the onus of additional configurations to the programmer. For example, Flask does not specify an ORM framework or include form validation right away. Such features are, however, supported through extensions that a programmer explicitly configures and integrates into the application.
What are the Core Features of Flask?
As a minimal framework, Flask supports basic web application functionality out of the box and includes only the modules strictly necessary for the same. These include:
- Werkzeug – the Python WSGI implementation that handles interactions between your web server and web applications.
- Jinja – a template language that renders your web pages.
- MarkupSafe – a library that provides character escaping functionality to guard against SQL injection attacks. MarkupSafe comes bundled with Jinja.
- ItsDangerous – a library used to protect Flask’s session cookie by securely signing data to ensure its integrity.
- Click – a framework for writing command line applications that provides the ‘Flask’ command and enables adding custom commands.
- Blinker – provides signaling support that enables components in modular applications to notify each other of events.
Any additional functionality can either be implemented by the developer from scratch or integrated via community-developed extensions. With over a thousand extensions available in the store, every essential use case is pretty much-taken care of.
Is Flask the Right Framework for Me?
Flask allows you to start small and scale progressively. This means eliminating unwanted dependencies that slow down your application and retaining control over your application by including only the dependencies you deem fit.
If you’re new to web development or are yet to acquaint yourself with the best programming paradigms, configuring every bit of functionality might be an overkill. In this scenario, it’s wise to pick opinionated frameworks like Django, which let you focus on the core functionality and take the onus of configuring an ideal application upon themselves.
But if you’re a seasoned developer, you’re bound to hold differing opinions about the ideal web application setup. And nine times out of ten, the default configuration that frameworks provide will need to be customized to your needs. In this scenario, starting off with the minimal setup offered by Flask and scaling it when you deem fit is the right thing to do.
Sometimes, the use case at hand is so simple that using a framework with extensive dependencies is simply overkill. For instance, you could be developing a web service only accessible within your company’s network and need no authentication. Or you could be creating a stateless application that doesn’t need to integrate with a database.
Flask allows these possibilities and actually presupposes them. Hence its growing popularity despite the availability of a comprehensive web framework like Django. Whether Flask is the right fit for you depends on the use case. But no matter where you are, getting your hands dirty with Flask could be a much-needed experience that teaches you the benefits of minimizing dependencies.
If you’re considering Flask for a critical enterprise project and are unsure of the long-term repercussions, you can reach out to our experts for a quick consultation here.