Skip to content

EasyPlay-AS/easyplay-python-fastapi

Repository files navigation

EasyPlay Python FastAPI

A lightweight FastAPI REST API for EasyPlay optimization services.

Prerequisites

  • Python 3.8+
  • pip

Setup

All in one command

python3 -m venv .venv
source .venv/bin/activate

python -m pip install --upgrade pip

pip install -r requirements.txt

fastapi dev main.py

Steps

  1. Clone the repository

    git clone <repository-url>
    cd easyplay-python-fastapi
  2. Create and activate virtual environment

    python -m venv .venv # or python3
    source .venv/bin/activate  # On Windows: source .venv\Scripts\activate
  3. Upgrade pip

    python -m pip install --upgrade pip
  4. Install dependencies

    pip install -r requirements.txt
  5. Install and setup AMPL

  • AMPL initiup setup

    # 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
  1. Run the development server

    fastapi dev main.py

The API will be available at http://127.0.0.1:8000/

API Endpoints

  • GET / - API information
  • POST /optimization - Optimization endpoint

Interactive Documentation

FastAPI automatically generates interactive API documentation:

  • Swagger UI: http://127.0.0.1:8000/docs
  • ReDoc: http://127.0.0.1:8000/redoc

Docker

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 container
  • easyplay-fastapi is the name of the image you just built

Railway Deployment

To deploy this application on Railway:

  1. Set up AMPL License

  2. Configure Railway Environment

    • In your Railway project, go to Variables tab
    • Add environment variable: AMPL_LICENSE_UUID with your license UUID
  3. 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
  4. Verify Deployment

    • Check the logs to ensure AMPL license is activated successfully
    • Test the /solve-example endpoint

Features

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •