A FastAPI-based REST API for managing Formula 1 drivers, teams, and rankings. Built as a learning project to explore modern Python backend development.
Note: Some architectural choices prioritize learning over best practices.
Web Framework | FastAPI 0.115.12 |
Database | PostgreSQL + SQLAlchemy 2.0.40 |
Validation | Pydantic 2.11.3 |
Testing | pytest 8.3.5 + httpx |
Server | Uvicorn (ASGI) |
Environment | python-dotenv |
Containerization | Docker + Docker Compose |
F1_API/
├── main.py # FastAPI application entry point
├── models.py # SQLAlchemy database models
├── schemas.py # Pydantic data validation schemas
├── crud.py # Database operations
├── database.py # Database connection and session management
├── rate_limit.py # Rate limiting middleware
├── requirements.txt # Python dependencies
├── Dockerfile # Container build instructions
├── docker-compose.yml # Multi-container orchestration
├── .dockerignore # Docker build context exclusions
├── .env.example # Environment variables template
├── .env # Environment variables (not in repo)
└── test/
├── conftest.py # pytest fixtures and test configuration
├── test_drivers.py # Driver endpoint tests
├── test_teams.py # Team endpoint tests
└── test_rankings.py # Rankings endpoint tests
- ✅ Create new drivers with validation
- ✅ Get driver by number
- ✅ List all drivers
- ✅ Associate drivers with teams
- ✅ Create teams with statistics
- ✅ Get team information
- ✅ List team drivers
- ✅ Track victories and championships
- ✅ Driver championship rankings
- ✅ Team championship standings
- ✅ Points-based ranking system
- ✅ Rate limiting middleware
- ✅ Comprehensive test suite
- ✅ Data validation with Pydantic
- ✅ PostgreSQL database integration
- ✅ Environment-based configuration
- ✅ Docker containerization
- ✅ Hot reload development
- Docker and Docker Compose installed
git clone https://github.com/AmineDELTA/F1_API.git
cd F1_API
# Copy environment template
cp .env.example .env
# Edit .env with your database credentials
# DATABASE_URL=postgresql://postgres:your_password@db:5432/F1_data
# POSTGRES_USER=postgres
# POSTGRES_PASSWORD=your_password
# POSTGRES_DB=F1_data
# Start the full application stack
docker-compose up --build
# Or run in background
docker-compose up --build -d
- API Documentation: http://localhost:8000/docs
- API Root: http://localhost:8000
- Database: localhost:5432
Use the Swagger UI at http://localhost:8000/docs to:
- Create teams using
POST /teams/create
- Create drivers using
POST /drivers/create
- Test endpoints like
GET /drivers/{number}
-
FastAPI Fundamentals
- Route definitions and path parameters
- Request/response models with Pydantic
- Dependency injection system
- Automatic API documentation
-
Database Integration
- SQLAlchemy ORM relationships
- Database session management
- Migration patterns
- Query optimization
-
Testing Best Practices
- Test isolation with database transactions
- Fixture design and dependency injection
- HTTP client testing with TestClient
- Mocking external dependencies
-
API Design
- RESTful endpoint patterns
- Error handling and status codes
- Data validation and serialization
- Rate limiting and middleware
AmineDELTA - GitHub Profile