Key Features
The Flask API provides enterprise-grade features out of the box:- RESTful Architecture: Clean, intuitive endpoints following REST principles
- Rate Limiting: Configurable request throttling to prevent abuse (default: 100 requests/minute)
- Response Caching: Built-in caching system to improve performance and reduce load
- CORS Support: Cross-Origin Resource Sharing enabled for web applications
- Multiple Export Formats: JSON, CSV, and PDF file exports for data portability
- Production Ready: Gunicorn integration for production deployments
- Flexible Configuration: YAML, dictionary, or environment variable configuration
API Endpoints
The API is organized into three main blueprint categories:Player Statistics
Goals
/players/goals - Get top goalscorers with filtering by season and leagueAssists
/players/assists - Get top assist providers with comprehensive stats/players/goals/csv_file, /players/goals/json_file, /players/assists/csv_file, /players/assists/json_file
Team Rankings
Full Standings
/ranking - Complete league table with detailed team statisticsTable View
/ranking/table - Simplified standings focused on essential stats/ranking/csv_file, /ranking/json_file, /ranking/pdf_file
Transfer Data
Team List
/all_teams - Get all teams in the league for a seasonTransfers
/transfers/in, /transfers/out - Track incoming and outgoing transfers/transfers/csv_file, /transfers/json_file
Architecture
Application Factory Pattern
The API uses Flask’s application factory pattern for flexible configuration:app.py:33 for the create_app function implementation.
Blueprint Structure
Endpoints are organized into three Flask blueprints for modularity:- players_bp (
routes/players.py:7) - Player statistics endpoints - transfer_bp (
routes/transfer.py:9) - Transfer data endpoints - ranking_bp (
routes/ranking.py:7) - League standings endpoints
Middleware Stack
The API automatically configures essential middleware:- CORS (
app.py:61) - Configurable cross-origin support - Cache (
app.py:62) - Response caching with configurable timeout - Rate Limiter (
app.py:63-67) - Request throttling per IP address
Configuration System
TheServerConfig class provides flexible configuration management:
Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
HOST | str | "0.0.0.0" | Server bind address |
PORT | int | 3000 | Server port number |
DEBUG | bool | False | Enable Flask debug mode |
SECRET_KEY | str | "default-secret-key" | Flask secret key for sessions |
CORS_ORIGINS | list | ["*"] | Allowed CORS origins |
JSON_SORT_KEYS | bool | False | Sort JSON response keys |
RATE_LIMIT | int | 100 | Requests per minute limit |
CACHE_TYPE | str | "simple" | Cache backend type |
CACHE_DEFAULT_TIMEOUT | int | 300 | Cache timeout in seconds |
LOG_LEVEL | str | "INFO" | Logging level |
config/config.py:8-21 for the complete ServerConfig dataclass.
Configuration Methods
The ServerConfig class supports multiple configuration sources: From Dictionary:config/config.py:24-56 for configuration loading implementations.
Rate Limiting
The API implements IP-based rate limiting using Flask-Limiter:- Default Limit: 100 requests per minute per IP address
- Customizable: Configure via
RATE_LIMITparameter - Automatic: Applied to all endpoints by default
- IP Detection: Uses
get_remote_addressfor client identification
app.py:63-67.
Caching Strategy
Response caching reduces load and improves performance:- Cache Type: Simple in-memory cache (configurable)
- Default Timeout: 300 seconds (5 minutes)
- Cache Backends: Supports Redis, Memcached, filesystem, etc.
app.py:54-55 and app.py:62.
CORS Configuration
Cross-Origin Resource Sharing is enabled for web applications:- Default: All origins allowed (
["*"]) - Production: Specify exact origins for security
- Automatic: Configured during app creation
app.py:61.
Production Deployment
The API includes Gunicorn integration for production use:StandaloneGunicornApp class (app.py:17-30) wraps Gunicorn for production deployments with:
- Multiple worker processes
- Sync worker class
- 120-second timeout
- App preloading for faster worker startup
app.py:112-119 for Gunicorn configuration.
Error Handling
All endpoints return consistent error responses: 400 Bad Request - Invalid parameters:Security Features
- Filename Sanitization: All file export endpoints use
secure_filenameto prevent directory traversal attacks - Request Validation: Query parameters are validated before processing
- Rate Limiting: Prevents abuse and DoS attacks
- CORS Configuration: Control which origins can access the API
Next Steps
Quickstart Guide
Get the API running locally in minutes
API Reference
Explore detailed endpoint documentation