FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints to validate, serialize, and deserialize data, and automatically auto-generate OpenAPI documents.
FastAPI has is one of the latest python api's for web development. It has some of this features:
It is fast when we compare it to other major Python frameworks like Flask and Django.
This is one of exciting feature of FastAPI that it supports asynchronous code out of the box using the async/await Python keywords.
It takes like 8 lines of code to comeup with a hello, word program
It has a feature of test driven development with the help using the TestClient provided by fastAPI.
It has one of the easiest documentation that one can understand.
You can easily deploy your FastAPI app via Docker using FastAPI provided docker image
First create a folder at your own location of choice
create a virtual environment inside the folder you created
activate the virtual environment created called env
Create a python file with the following code and save as myapp.py
Then to run the server, we use the following command:
To know it it works with no error, you will see this in your commandline
Now to open in browser, use the following link
you will see the following output
before going to docker, we can create a requirement.txt file that has all the tools that you have installed in one place by running;
Docker is an open source platform for building ,deploying and managing containerized applications.
Docker container is a virtualized runtime environment that provides isolation capabilities for separating the execution of applications from the underpinning system
Create a docker file and save with this commands
Then build your image