A FastAPI-based REST API for querying CMA CGM port pair booking data.
- 🚀 Fast API endpoints for port pair data retrieval
- 📊 Query specific port pairs or search by origin/destination
- 🔍 Get lists of all available port pairs and dates
- ✅ Health check endpoint for monitoring
- 🌐 CORS enabled for frontend integration
GET /- API information and available endpointsGET /health- Health check (returns service status)GET /port-pairs- List all available port pairsGET /port-pairs/{port_pair}- Get data for specific port pair (e.g.,/port-pairs/BJCOO-BRPEC)GET /dates- List all available datesGET /search?origin={code}&destination={code}- Search port pairs by origin/destination
# Get all port pairs
curl https://your-app.railway.app/port-pairs
# Get specific port pair data
curl https://your-app.railway.app/port-pairs/BJCOO-BRPEC
# Search by origin
curl https://your-app.railway.app/search?origin=CIABJ
# Search by destination
curl https://your-app.railway.app/search?destination=BRPEC
# Health check
curl https://your-app.railway.app/health- Python 3.11 or higher
- pip (Python package manager)
-
Clone or navigate to the project directory
cd /path/to/SpotOn -
Create a virtual environment
python3 -m venv venv
-
Activate the virtual environment
On macOS/Linux:
source venv/bin/activateOn Windows:
venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run the application
python main.py
Or using uvicorn directly:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
-
Access the API
- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- Alternative docs: http://localhost:8000/redoc
-
Install Railway CLI (optional, but recommended)
npm i -g @railway/cli
-
Login to Railway
railway login
-
Initialize and deploy
railway init railway up
- Push your code to a GitHub repository
- Go to Railway.app
- Click "New Project" → "Deploy from GitHub repo"
- Select your repository
- Railway will automatically detect the Procfile and deploy
If needed, you can set environment variables in Railway dashboard:
PORT- Port number (Railway sets this automatically)
SpotOn/
├── main.py # FastAPI application
├── requirements.txt # Python dependencies
├── Procfile # Railway deployment config
├── .python-version # Python version specification
├── .gitignore # Git ignore rules
├── README.md # This file
├── POLPODS.py # Original script (can be removed)
└── Qlik Sense Port Pairs SpotOn.csv # Data file
The API expects a CSV file (Qlik Sense Port Pairs SpotOn.csv) with:
- First row: header with dates
- First column: POL-POD Booked (port pair identifiers in format: ORIGIN-DESTINATION)
- Data: percentage values for each date
- FastAPI - Modern, fast web framework for building APIs
- Uvicorn - ASGI server for running the application
- Pandas - Data manipulation and analysis
- NumPy - Numerical computing support
FastAPI automatically generates interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
You can test all endpoints directly from the Swagger UI at /docs, or use tools like:
- curl (command line)
- Postman
- HTTPie
- Your browser (for GET requests)
To update dependencies:
pip install --upgrade -r requirements.txt
pip freeze > requirements.txtIf port 8000 is already in use, specify a different port:
uvicorn main:app --reload --port 8001Ensure Qlik Sense Port Pairs SpotOn.csv is in the same directory as main.py.
If you have issues with the virtual environment:
deactivate # if currently activated
rm -rf venv
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtInternal use for CMA CGM data analysis.
For issues or questions, contact the development team.