Prerequisites
Before setting up the development environment, ensure you have the following installed:- Python 3.10 - The API is built on Python 3.10
- MySQL 5.7+ - Primary relational database
- MongoDB 6.0+ - Document storage for catalog and user data
- Redis 7.2+ - Caching and session management
- Git - Version control
Installation Steps
Install Dependencies
Install all required Python packages from
requirement.txt:Key Dependencies
Key Dependencies
The project uses the following core dependencies:
- Web Framework: Falcon 3.1.1 with auth, CORS, multipart support
- Database: SQLAlchemy 1.4.53, PyMySQL 1.1.0, pymongo 4.6.1
- Task Queue: Celery 5.3.6 with Redis backend
- Caching: Redis 5.0.1, Beaker 1.12.1
- AWS Services: boto3 1.34.34 for S3, Kinesis
- GraphQL: graphene 3.3 for API layer
- Search: elasticsearch 6.8.2
- WSGI Server: gunicorn 21.2.0
Configure Environment Variables
Copy the example environment file and configure your local settings:Edit
.env with your local database credentials. See Configuration Reference for all available options.Run Database Migrations
Apply database migrations to set up the schema:This will create all necessary tables in your MySQL database.
Running the Application Locally
Start the API Server
The application uses Gunicorn as the WSGI server. Start the development server:Gunicorn Configuration
The recommended Gunicorn settings for development:- Workers (
-w): 4 (adjust based on CPU cores) - Threads (
-t): 8 per worker - Bind (
-b):0.0.0.0:8001(accessible on all interfaces) - Timeout: 1200 seconds (20 minutes for long-running requests)
- Log Level:
debugfor development,infofor staging
Start Celery Workers
For background task processing, start Celery workers in a separate terminal:Start Flower (Optional)
Monitor Celery tasks with Flower:http://localhost:5555
Verify Setup
Once the server is running, verify the installation:Health Check
API Endpoints
The API exposes endpoints under the following prefixes:/api/v2/*- Main API v2 endpoints/api/v3/*- New API v3 endpoints/api/v2/haptik/*- Haptik integration endpoints/api/v2/external/*- External API endpoints
Development Tools
Database Connection Pooling
The application uses SQLAlchemy connection pooling with the following defaults:- Pool Size: 5 connections (configurable via
POOL_SIZE) - Max Overflow: 30 connections (configurable via
MAX_OVERFLOW) - Auto Commit: Enabled
- Echo: Disabled (set
DB_ECHO=Truefor SQL logging)
Timezone Configuration
The application usesAsia/Kolkata (IST) as the default timezone. All timestamps are stored in UTC and converted as needed.
Troubleshooting
Port Already in Use
Port Already in Use
If port 8001 is already in use, either stop the conflicting process or change the port:
Database Connection Errors
Database Connection Errors
Ensure your database services are running and credentials in
.env are correct:Module Import Errors
Module Import Errors
If you encounter import errors, ensure your virtual environment is activated and all dependencies are installed:
Protobuf Compatibility Issues
Protobuf Compatibility Issues
The application requires Python implementation for protobuf (used by pydgraph). This is set automatically via environment variable:This is included in the Dockerfile but should be set manually for local development if you encounter protobuf errors.
Next Steps
- Review the Configuration Reference for all environment variables
- Learn about Deployment for production setup
- Explore the API endpoints in the API Reference section