This small piece of API contains all basic features that API's must have. App is created in FastAPI Python framework. Database (PostgreSQL in our case) connection handled using SQL Alchemy. Pydantic used for data parsing and validation.
- Clone the repository to your development environment:
git clone https://github.com/perviz3003/python-fastapi-api.git
cd
into that folder and create virtual environment:
cd python-fastapi-api
python3 -m venv venv
- Activate environment and install all required packages from Requirements.txt file using the package manager pip:
source env/bin/activate
pip install -r Requirements.txt
If you have installed all required packages successfully, you should simply execute below command in terminal:
uvicorn api.main:app --reload
Now you can access your api from web browser: http://127.0.0.1:8000
FastAPI provides two beautiful API interface which generate API Docs automatically:
- Swagger UI - http://127.0.0.1:8000/docs
- ReDoc - http://127.0.0.1:8000/redoc