Python API

Install

HiGHS is available as highspy on PyPi.

If highspy is not already installed, run

pip install highspy

Import

To use highspy within a Python program, it must be imported

import highspy

When using highspy, it is likely that numpy structures will be needed, so must also be imported

import numpy as np

Initialize

HiGHS must be initialized before making calls to the HiGHS Python library

h = highspy.Highs()

Methods

Detailed documentation of the methods and structures is given in the [examples section]](@ref example-py).

Return status

Unless a method just returns data from HiGHS, so is guaranteed to run successfully, each method returns a status to indicate whether it has run successfully. This value is an instance of the enum HighsStatus, and in the [examples section]](@ref example-py), it is referred to as status.

First example

The following Python code reads a problem from the file model.mps, and then solves it.

import highspy
import numpy as np

# Highs h
h = highspy.Highs()

# Load a model from MPS file model.mps
filename = 'model.mps'
status = h.readModel(filename)
status = h.run()
print('Model ', filename, ' has return status ', h.modelStatusToString(h.getModelStatus))