FastAPI-based web service for running SUMO (Simulation of Urban MObility) traffic simulations.
- β Upload ZIP files containing SUMO simulation configurations
- β Run SUMO simulations via REST API
- β Download simulation output files
- β Modern web interface with drag & drop support
- β Docker containerized deployment
- β CORS enabled for frontend integration
- β Comprehensive logging
sumoweb-api/
βββ app/
β βββ api/ # API route handlers
β β βββ files.py # File upload/download endpoints
β β βββ simulation.py # Simulation execution endpoints
β βββ core/ # Core configurations
β β βββ config.py # Application settings
β βββ utils/ # Utility functions
β β βββ file_handler.py # File operations
β β βββ sumo_runner.py # SUMO execution logic
β βββ main.py # FastAPI application entry
βββ frontend/ # Frontend files
β βββ index.html # Modern web interface
βββ uploads/ # Upload directory (auto-created)
βββ Dockerfile # Docker build configuration
βββ docker-compose.yml # Docker compose setup
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ README.md # This file
- Docker and Docker Compose
- OR Python 3.8+ with SUMO installed locally
-
Build and run with Docker Compose
docker-compose up --build
-
Access the application
- Web Interface: Open
frontend/index.htmlin your browser - API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
- Web Interface: Open
docker build -t sumo-api .
docker run -p 8000:8000 -v ./uploads:/workspace/uploads sumo-api-
Install dependencies
pip install -r requirements.txt
-
Install SUMO
- Ubuntu:
sudo add-apt-repository ppa:sumo/stable && sudo apt-get install sumo sumo-tools - Windows/Mac: Download from https://sumo.dlr.de/docs/Downloads.php
- Ubuntu:
-
Run the server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
-
Start the API server (using Docker or locally as shown above)
-
Open the web interface
Simply open
frontend/index.htmlin your browser:# Windows start frontend/index.html # macOS open frontend/index.html # Linux xdg-open frontend/index.html
Or serve it with Python's HTTP server:
# From project root python -m http.server 8080 --directory frontendThen visit: http://localhost:8080
-
Use the interface
- Drag and drop your ZIP file or click to browse
- Click "Run Simulation" button
- Watch the progress bar as simulation runs
- Download output files when complete
curl -X POST "http://localhost:8000/upload/" \
-H "Content-Type: multipart/form-data" \
-F "file=@simulation.zip"curl "http://localhost:8000/run_simulation/"curl "http://localhost:8000/output_files"curl "http://localhost:8000/download/edgedata.out.xml" -o output.xml- Import the API endpoints
- Upload: POST to
http://localhost:8000/upload/with file in form-data - Simulate: GET to
http://localhost:8000/run_simulation/ - Download: GET to
http://localhost:8000/download/{filename}
Visit http://localhost:8000/docs to use Swagger UI:
- Test all endpoints interactively
- See request/response schemas
- Try different parameters
POST /upload/
Content-Type: multipart/form-data
Body: file (ZIP containing SUMO configuration files)Response:
{
"status": "success",
"message": "File uploaded and extracted successfully"
}GET /output_filesResponse:
{
"files": ["edgedata.out.xml", "fc.out.xml"]
}GET /download/{filename}GET /run_simulation/Response:
{
"status": "success",
"message": "Simulation completed successfully!",
"output_files": ["edgedata.out.xml"]
}GET /healthResponse:
{
"status": "healthy",
"version": "1.0.0"
}GET /Response:
{
"name": "SUMO Web API",
"version": "1.0.0",
"status": "running"
}The modern web interface (frontend/index.html) includes:
- π¨ Beautiful Design: Modern gradient background with card-based layout
- π¦ Drag & Drop: Simply drag your ZIP file onto the upload area
- π Progress Tracking: Real-time progress bar with status updates
- β¨ Animations: Smooth transitions and visual feedback
- π± Responsive: Works perfectly on desktop, tablet, and mobile
- β¬οΈ Easy Downloads: One-click download for all output files
- π No Build Required: Pure HTML/CSS/JavaScript, no dependencies
Copy .env.example to .env and customize:
DEBUG=False
LOG_LEVEL=INFO
CORS_ORIGINS=*
SUMO_HOME=/usr/share/sumoEdit app/core/config.py to modify:
- Upload directory
- File size limits
- Allowed file extensions
- SUMO timeout duration
Your ZIP file should contain:
0.sumocfg- Main SUMO configuration file- Network file (
.net.xml) - Route file (
.rou.xml) - Additional files as needed (vtypes, edge data, etc.)
Example structure:
simulation.zip
βββ 0.sumocfg
βββ network0.xml
βββ Routes.Rou.xml
βββ vtypes.add.xml
βββ edgedata.add.xml
Problem: Frontend can't connect to API (CORS errors)
Solution: Ensure the API is running on localhost:8000 and check browser console for errors.
# Change port in docker-compose.yml or use:
docker-compose up -p 8001:8000
# Then update API_BASE in frontend/index.html to:
const API_BASE = 'http://localhost:8001';chmod 777 uploads/Ensure SUMO_HOME environment variable is set correctly:
echo $SUMO_HOME
which sumo# Clean build
docker-compose down
docker system prune -a
docker-compose up --build- Check file is a valid ZIP
- Ensure ZIP contains
0.sumocfg - Verify file size is under 100MB
- Check API logs for detailed errors
pytest tests/black app/flake8 app/# Docker Compose
docker-compose logs -f sumo-api
# Docker
docker logs -f <container_id>
# Local
# Logs appear in terminal where uvicorn is running- In production, update
CORS_ORIGINSto specific domains - Add authentication for sensitive endpoints
- Implement file size validation
- Use HTTPS in production
- Consider rate limiting for public deployments
- Update CORS settings in
app/core/config.py - Set environment variables properly
- Use a reverse proxy (nginx, Traefik)
- Enable HTTPS
- Add authentication if needed
- Monitor logs and metrics
-
Start the API
docker-compose up
-
Open the web interface
- Open
frontend/index.htmlin your browser
- Open
-
Upload your simulation
- Drag your ZIP file containing SUMO config
- Click "Run Simulation"
-
Monitor progress
- Watch the animated progress bar
- See real-time status updates
-
Download results
- Click download on any output file
- Files are saved to your downloads folder
MIT
For issues and questions:
- GitHub Issues: [Create an issue]
- SUMO Documentation: https://sumo.dlr.de/docs/
- Initial release
- Modern web interface with drag & drop
- File upload and extraction
- SUMO simulation execution
- Output file management
- Docker support
- Comprehensive error handling