Python / FastAPI codebase containing real world examples (CRUD, auth, middlewares advanced patterns, etc.) that adheres to the RealWorld spec and API.
This codebase was created to demonstrate a fully fledged backend application built with FastAPI including CRUD operations, authentication, routing, and more.
For more information on how this works with other frontends/backends, head over to the RealWorld repo.
This project is a Python-based API that uses PostgreSQL as its database. It is built with FastAPI, a modern, fast (high-performance), web framework for building APIs with Python 3 based on standard Python type hints.
- Python 3.12
- FastAPI
- PostgreSQL
- Pytest
- Docker
Create a virtual environment:
make ve
Install dependencies:
pip install -r requirements.txt
Replace .env.example
with real .env
, changing placeholders
SECRET_KEY=your_secret_key
POSTGRES_USER=your_postgres_user
POSTGRES_PASSWORD=your_postgres_password
POSTGRES_DB=your_postgres_db
POSTGRES_HOST=your_postgres_host
POSTGRES_PORT=your_postgres_port
JWT_SECRET_KEY=your_jwt_secret_key
You must have docker
and docker-compose
installed on your machine to start this application.
Setup PostgreSQL database with docker-compose:
make docker_build_postgres
Run the migrations:
make migrate
Run the application server:
make runserver
Also, you can run the fully Dockerized application with docker-compose
:
make docker_build
And after that run migrations:
docker exec -it conduit-api alembic upgrade head
Tests for this project are defined in the tests/
folder.
For running tests, you can have to create separate .env.test
file the same as .env
file, but with different database name.:
POSTGRES_DB=conduit_test
Then run the tests:
make test
Or run the tests with coverage:
make test-cov
For running tests for local application:
APIURL=http://127.0.0.1:8000/api ./postman/run-api-tests.sh
For running tests for fully Dockerized application:
APIURL=http://127.0.0.1:8080/api ./postman/run-api-tests.sh
All routes are available on / or /redoc paths with Swagger or ReDoc.