A lightweight FastAPI REST API for EasyPlay optimization services.
- Python 3.8+
- pip
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
fastapi dev main.py
-
Clone the repository
git clone <repository-url> cd easyplay-python-fastapi
-
Create and activate virtual environment
python -m venv .venv # or python3 source .venv/bin/activate # On Windows: source .venv\Scripts\activate
-
Upgrade
pip
python -m pip install --upgrade pip
-
Install dependencies
pip install -r requirements.txt
-
Install and setup AMPL
-
# Install Python API for AMPL python -m pip install amplpy --upgrade # Install SCIP (AMPL is installed automatically with any solver) python -m amplpy.modules install scip # Activate your license (e.g., free https://ampl.com/ce license) python -m amplpy.modules activate <license-uuid> # Confirm that the license is active python -m amplpy.modules run ampl -vvq
-
Run the development server
fastapi dev main.py
The API will be available at http://127.0.0.1:8000/
GET /
- API informationPOST /optimization
- Optimization endpoint
FastAPI automatically generates interactive API documentation:
- Swagger UI:
http://127.0.0.1:8000/docs
- ReDoc:
http://127.0.0.1:8000/redoc
Builder the Docker Image
docker build -t easyplay-fastapi .
-t easyplay-fastapi
tags your image with the name "easyplay-fastapi".
tells Docker to use the current directory as the build context
Run the Docker Container
docker run -d -p 8000:8000 easyplay-fastapi
-p 8000:8000
maps port 8000 from your host machine to port 8000 in the containereasyplay-fastapi
is the name of the image you just built
To deploy this application on Railway:
-
Set up AMPL License
- Get a free AMPL Community Edition license from https://ampl.com/ce
- Copy your license UUID
-
Configure Railway Environment
- In your Railway project, go to Variables tab
- Add environment variable:
AMPL_LICENSE_UUID
with your license UUID
-
Deploy
- Connect your GitHub repository to Railway
- Railway will automatically detect the
nixpacks.toml
configuration - The deployment will install AMPL, SCIP solver, and activate your license using the environment variable
-
Verify Deployment
- Check the logs to ensure AMPL license is activated successfully
- Test the
/solve-example
endpoint
- ⚡ Fast: One of the fastest Python frameworks
- 🔧 Type hints: Full Python type support
- 📚 Auto docs: Automatic OpenAPI/Swagger documentation
- ✅ Validation: Automatic request/response validation
- 🔒 Security: Built-in security features
- 🚀 Railway Ready: Pre-configured for Railway deployment with AMPL