liveBook · Manning

Flask

As explained in Software Engineering for Data Scientists

Flask is a lightweight Python web framework for building web applications and APIs.

Flask is a lightweight Python library for building web applications. Its small footprint makes it approachable when data scientists need a first web interface without extensive web-development background. section 13.1

A basic Flask workflow follows a short, practical sequence:

  • Install Flask with pip. section 13.1.1
  • Create a central Flask application object and map URL routes to Python functions. section 13.1.1
  • Return a message or HTML from each route, then launch the application with python app.py. section 13.1.1
  • Expand the prototype into multiple webpages using links, headings, and dashboard routes. section 13.3.1

Minimal Flask application

from flask import Flask app = Flask(__name__) @app.route('/') def main_page(): return "Sample dashboard application" if __name__ == '__main__': app.run() Running python app.py makes the page available locally at http://127.0.0.1:5000. section 13.1.1

Listing 13.2 For this example, we are creating a basic application that shows a message on a webpage.
from flask import Flask #1

app = Flask(__name__) #2

@app.route('/') #3
def main_page(): #4
    return "Sample dashboard application" #5

if __name__ == '__main__': #6
    app.run() #6

Use the complete starter listing to inspect Flask imports, application creation, route declaration, response text, and application launch. section 13.1.1

How Software Engineering for Data Scientists covers it

How deep it goes
Demonstrates installation, application creation, routing, local launch, and multipage HTML before moving toward more complex applications.
Examples
Uses a message page, local development server, and multipage dashboard with metrics, data-view, and machine-learning links.
What it assumes
Assumes Python and terminal use while minimizing required web-development background.
What you can do after
Build it from scratch by installing Flask, defining routes, returning webpage content, and launching a local application.
How it connects
Connects Python web applications to HTML, JavaScript, WSGI, and Waitress.

Also explained in

Compare how 6 books explain Flask →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Engineering for Data Scientists. The section links point to the parts of the book it draws on.