Hello, This is test project for TopTal by Mate Bersenadze.
Test project is about Quiz API.
To say it shortly, Users can create Quizzes, other users can play it and gain scores.
Python version: 3.10.4
For RESTful application newly created Web Framework: FastAPI by Tiangolo
For Database: PostgreSQL
For Migrations: Alembic
For Code Formatting: Black and Flake8 backed by Pre-Commit
To run PostgreSQL I am using docker containers locally.
Python 3.10 is REQUIRED to run application
Create virtualenv named venv
virtualenv venv --python=python3.10
Activate environment
source venv/bin/activate
First, to run application we need to install all the requirements.
You may need to update pip before running install.
pip install --upgrade pip
pip install -r requirements.txt
You can also use already ready created PostgreSQL DB, but in this step we gonna run fresh empty DB.
You will need to have Docker engine installed and running.
To run DB execute this in terminal
docker run --name toptal-quiz-postgres -e POSTGRES_PASSWORD=toptal -p 5432:5432 -d postgres
This will run postgres DB on port 5432 with user: postgres and password: toptal You can configure password or port that is being used.
Applications requires Environment variables. DB_URI and SECRET_KEY
- DB_URI is being used to connect to our created DB.
- SECRET_KEY is being used for jwt encode and decodings during authentication.
SECRET_KEY can be generated using this command
openssl rand -hex 32
Example .env File
DB_URI=postgresql://postgres:toptal@localhost:5432/postgres
SECRET_KEY=040ce4734a42f6fe46b6b54925aa2383fa88f08c04bbf3e1f18b2e9fca0213d8
After you have successfully created and run PostgreSQL DB now you have to create all required tables. For this we can use Alembic which was already installed in the previous step.
Just execute in terminal
alembic upgrade head
uvicorn server:app --port 8000
Running server like this on production is not recommended
We can see our API Documentation in Redoc or Swagger style
Redoc: http://127.0.0.1:8000/redoc Swagger: http://127.0.0.1:8000/docs