Skip to main content

Flask

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/flask

In short

Flask is a lightweight Python web framework offering routing, request handling and templates, leaving the database and project structure to the developer.

What is Flask?

Flask was written by Armin Ronacher and released in 2010, and it is maintained by the Pallets project. It calls itself a microframework: the core is small and built on two libraries, Werkzeug for the HTTP and WSGI plumbing and Jinja for HTML templates. A complete app can be a single file with a few decorated functions.

Routes are declared with decorators such as @app.route("/books/<int:id>"), and the function returns a string, a template or a dictionary that Flask turns into JSON. Everything else comes from extensions: Flask-SQLAlchemy for databases, Flask-Login for sessions, Flask-WTF for forms. Blueprints split larger apps into modules.

Flask is popular for small web apps, internal tools, prototypes, teaching and simple APIs, and for wrapping machine learning models behind an HTTP endpoint. Its explicit, unmagical style makes it easy to see what happens on each request, which is why many Python developers learn web development with it.

A common misconception is that Flask is only for toy projects. Large applications run on it too; it simply asks the team to choose and organize the pieces that Django includes out of the box. It runs behind a production WSGI server such as Gunicorn, not the built-in development server.

Key takeaways

  • Flask is a lightweight Python web framework released in 2010.
  • It is built on Werkzeug for HTTP and Jinja for templates.
  • Routes are functions marked with decorators such as @app.route.
  • Databases, auth and forms come from extensions you choose.
  • Production apps run behind a WSGI server such as Gunicorn.

Example

A minimal Flask apppython
from flask import Flask, jsonify, render_template

app = Flask(__name__)

BOOKS = {1: "Dune", 2: "Neuromancer"}

@app.route("/")
def home():
    return render_template("index.html", books=BOOKS)   # Jinja template

@app.route("/api/books/<int:book_id>")
def book(book_id):
    if book_id not in BOOKS:
        return jsonify(error="Not found"), 404
    return {"id": book_id, "title": BOOKS[book_id]}       # returned as JSON

# Development:  flask --app app run --debug
# Production:   gunicorn app:app

Readers ask

What is the difference between Flask and Django?

Flask is minimal and lets you pick your own database layer, forms and structure. Django includes an ORM, admin panel, authentication and a fixed project layout. Flask gives flexibility; Django gives more ready-made features.

Is Flask good for APIs?

Yes, especially small and medium ones. For APIs that need automatic validation and generated documentation, FastAPI is often chosen instead.

What is WSGI?

The Web Server Gateway Interface, the standard way Python web apps talk to web servers. Flask apps are WSGI apps and run on servers such as Gunicorn or uWSGI.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings