This is the first part of a series about the Flask framework, a common tool used to create web applications with Python.
In this series you will learn how to create a web API in Python, make requests and connect it with local and remote databases.
The part 1 will focus on the virtual environment to install Flask and how to run a web API.
The full example is available here: Python-Flask.
If you are new to Python, read these articles to get started: Python for Beginners.
Create a folder for your project, open VSCode and execute the command below to create a virtual environment (venv):
python -m venv venv
Confirm any popup that shows up and run the command below to use the venv:
Create a file named 'requirements.txt' containing the word flask.
Install the flask package inside the venv with the following command:
pip install -r requirements.txt
The result will be:
Create a folder called api with a file called api.py. Inside the file, write this code:
Run the following command:
If you follow the URL displayed you will see the web page running:
We will create the HTTP methods to turn our web application into a web API.