Prerequisites
Before you begin, ensure you have the following installed:- Python 3.10 or higher
- PostgreSQL 15 or higher
- Git
- pip and virtualenv
System Requirements
- OS: Windows, Linux, or macOS
- RAM: Minimum 4GB (8GB recommended)
- Storage: 1GB for application and dependencies
- Network: Internet connection for initial data scraping
Installation
# Create virtual environment
python -m venv venv
# Activate on Linux/Mac
source venv/bin/activate
# Activate on Windows
venv\Scripts\activate
# Connect to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE fkapi;
# Create user (optional)
CREATE USER fkapi_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE fkapi TO fkapi_user;
# Exit
\q
# Django Settings
DJANGO_DEBUG=True
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1
DJANGO_PORT=8000
DJANGO_API_ENABLE_AUTH=False
# PostgreSQL Database
POSTGRES_DB=fkapi
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
# Redis (optional)
REDIS_URL=redis://localhost:6379/1
REDIS_PORT=6379
# Celery (optional)
ENABLE_CELERY=False
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0
For development, you can disable Redis and Celery. FKApi will automatically fall back to local memory cache and threading.
Verification
Verify your installation by testing these endpoints:Health Check
Test API Endpoints
Production Configuration
For production deployments, update your.env file:
Running with Gunicorn (Production)
For production, use Gunicorn instead of the development server:--workers 4: Number of worker processes (recommended: 2-4 x CPU cores)--timeout 120: Worker timeout in seconds--bind 0.0.0.0:8000: Bind to all interfaces on port 8000
Next Steps
Docker Deployment
Deploy FKApi using Docker and docker-compose
Celery Setup
Configure async tasks with Celery
Caching Strategy
Optimize performance with Redis caching
Monitoring
Set up Prometheus and Grafana monitoring
Troubleshooting
Database Connection Errors
If you see connection errors:- Verify PostgreSQL is running:
sudo systemctl status postgresql(Linux) orpg_ctl status(Windows) - Check database credentials in
.env - Ensure database exists:
psql -U postgres -l - Check PostgreSQL is listening on the correct port:
netstat -an | grep 5432
Module Import Errors
If you seeModuleNotFoundError:
- Ensure virtual environment is activated
- Reinstall requirements:
pip install -r requirements.txt - Verify Python version:
python --version(should be 3.10+)
Port Already in Use
If port 8000 is already in use:- Change port in
.env:DJANGO_PORT=8001 - Or run with custom port:
python manage.py runserver 8001 - Find and kill process using port:
lsof -ti:8000 | xargs kill(Linux/Mac)
Permission Errors
On Linux/Mac, you may need to:Environment Variables Reference
| Variable | Default | Description |
|---|---|---|
DJANGO_SECRET_KEY | (auto-generated in dev) | Secret key for Django security |
DJANGO_DEBUG | True | Enable debug mode |
DJANGO_ALLOWED_HOSTS | localhost,127.0.0.1 | Comma-separated list of allowed hosts |
DJANGO_PORT | 8000 | Port for development server |
DJANGO_API_ENABLE_AUTH | False | Enable API authentication |
POSTGRES_DB | fkapi | PostgreSQL database name |
POSTGRES_USER | postgres | PostgreSQL username |
POSTGRES_PASSWORD | postgres | PostgreSQL password |
POSTGRES_HOST | localhost | PostgreSQL host |
POSTGRES_PORT | 5432 | PostgreSQL port |
REDIS_URL | redis://localhost:6379/1 | Redis connection URL |
ENABLE_CELERY | False | Enable Celery for async tasks |
CELERY_BROKER_URL | redis://localhost:6379/0 | Celery message broker |
CELERY_RESULT_BACKEND | redis://localhost:6379/0 | Celery result storage |