Flask, Web development, one drop at a time.

Flask For Simple Web Apps

Quick Overview Of Flask

The most popular web framework

Contact us

Intro

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. However, Flask supports extensions that can add application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, various open authentication technologies and several common framework related tools.

Components

- Werkzeug,
- Jinja,
- MarkupSafe,
- ItsDangerous

Features

- Development server and debugger,
- Integrated support for unit testing,
- RESTful request dispatching,
- Uses Jinja templating,
- Support for secure cookies (client side sessions),
- 100% WSGI 1.0 compliant,
- Unicode-based,
- Extensive documentation,
- Google App Engine compatibility,
- Extensions available to enhance features desired

Advantages of Flask

Higher compatibility with latest technologies

Technical experimentation

Easier to use for simple cases

Codebase size is relatively smaller

High scalability for simple applications

Easy to build a quick prototype

Routing URL is easy

Easy to develop and maintain applications

Database integration is easy

Small core and easily extensible

Minimal yet powerful platform

Lots of resources available online especially on GitHub

Why Flask

What's special about Flask?

Flask is a simple and minimalist web framework written in Python. It has no database abstraction layer, form validation, or other components that a web app might require. However, Flask can be enhanced with extensions that can add application features as if they were implemented in Flask itself. It's open source under a BSD license.

Flask is easy to set up and learn. One can write a Flask app in as few as seven lines of code and extend it to thousands. Among the big companies that use Flask are LinkedIn, Pinterest, Reddit, and many more.

Flask along with Bootstrap and SQLite can be used to easily develop full-functioning web apps.

Flask Components

Components

Performance Optimization

When Flask app runs slow we need to identify what is the bottleneck. It can be an overloaded database, unresponsive external API, or heavy, CPU-intensive computation. This is the whole recipe on how to speed up Flask - find the source of sluggish performance. After the bottleneck is identified you can fight an underlying cause.

Getting slow SQL queries

Since now we know that querying the database slows us down let’s investigate what queries we execute. There is an SQLAlchemy feature that allows us to get all the queries executed during the request.

Flask-DebugToolbar

More high-level tools can profile Flask. One of them is a flask-debugtoolbar.

This extension adds a toolbar overlay to Flask applications containing useful information for debugging.

The toolbar will automatically be injected into Jinja templates when debug mode is on.

Getting slow SQL queries

Since now we know that querying the database slows us down let’s investigate what queries we execute.
There is an SQLAlchemy feature that allows us to get all the queries executed during the request.

DB Queries

In case if slow DB queries - use EXPLAIN to see if the server uses the index for querying the data.

Or you may spin up a read-replica DB to steer read requests to it if you’ve reached a limit with vertical scaling of the DB server.

If it’s a slow API or CPU intensive job - consider putting it in an async background job.

View dependencies and service relationships across your systems

If your Flask applications are underperforming, you need to know what’s causing the problem right away. The AppOptics visual service map auto-detects the relationships and dependencies between your services, databases, domains, and cache, making it easier to locate unexpected resource drains.

Customize your monitoring to better align with the particulars of your application

Flask extensions allow you to create highly customized applications, and to ensure your applications are operating efficiently, you need an application performance monitoring (APM) tool designed to support the needs of your specific deployment.

TOP