A small FastAPI project that builds and tests an asynchronous API with Postgres, Docker, and pytest.
This is a learning-focused CRUD sample that shows how to:
- Build async endpoints with FastAPI.
- Connect to Postgres with async drivers.
- Write API tests with pytest and httpx.
- Run everything with Docker Compose.
- src/app: FastAPI application code
- src/test: pytest tests
- src/requirements.txt: Python dependencies
- src/Dockerfile: app container image
- docker-compose.yml: app + database services
- Build and start the stack
docker-compose up --build- Check the API
http http://localhost:8002/ping- Create a note
http --json POST http://localhost:8002/notes/ title=foo description=barYou can run tests inside the app container:
docker exec -it fastapi-crud-web-1 pytest- The app uses a bind mount in Docker Compose, so code changes apply immediately.
- If you change dependencies, rebuild the image.