DEV Community

Cover image for Python + Flask - Part 1 - Web API
LUCIANO DE SOUSA PEREIRA
LUCIANO DE SOUSA PEREIRA

Posted on • Originally published at lucianopereira.netlify.com

25 8

Python + Flask - Part 1 - Web API

titulo

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.

venv01

Install the flask package inside the venv with the following command:

pip install -r requirements.txt

The result will be:

venv02

API

Create a folder called api with a file called api.py. Inside the file, write this code:

flask01

Run the following command:

python .\api\api.py

The result will be:
flask02

If you follow the URL displayed you will see the web page running:

http://127.0.0.1:5000/

flask03

Next

We will create the HTTP methods to turn our web application into a web API.

References

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay