Within the field of data science, it is common to be required to use a selection of tools, each specific to their job. A role requiring visualisation using a web interface, but processing of a Python script, it is often better to build a bespoke visualisation in d3 or THREE.js to display it and then fetch data as required. This article covers the creation of a simple flask app that can serve data to a web interface using the Fetch API.

Creating a Flask app

We start by building a repository containing an empty templates folder and an app.py file.

App.py

Our app.pyfile contains the data required to create a web interface. To do this we use the flask ( pip install flask ) python library. For this we can use the following template:

#########  imports  ########
from flask import Flask, jsonify, request, render_template
app = Flask(__name__)

##########  run app  ########
app.run(debug=True)

#javascript #flask #fetch #python #towards-data-science

Talking to Python from Javascript: Flask and the fetch API
26.05 GEEK