This is the first part of a series about the Flask framework, a common tool used to create web applications with Python.
Objectives
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.
Before Start
If you are new to Python, read these articles to get started: Python for Beginners.
Topics
venv
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:
.\venv\Scripts\Activate.ps1
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:
API
Create a folder called api with a file called api.py. Inside the file, write this code:
Run the following command:
python .\api\api.py
If you follow the URL displayed you will see the web page running:
http://127.0.0.1:5000/
Next
We will create the HTTP methods to turn our web application into a web API.
Top comments (0)