This section contains an overview of the architecture of the solvers API on Python; the classes are similar to the cpp version (shown here) but are split in separate modules.

So far, the publicly available python packages are amplpy-gurobi and amplpy-cplex.

This diagram shows the available classes in three groups:

graph G {
  subgraph clusterBase {
    AMPLModel BaseCallback GenericCallback;
  subgraph clusterGurobi {
      GurobiModel  GurobiCallback "Gurobi C entry points"
  subgraph clusterCplex {
    CPLEXModel CPLEXCallback "CPLEX C entry points"

  clusterBase -- clusterGurobi
  clusterBase -- clusterCplex

both amplpy-gurobi and amplpy-cplex contain the base group and the solver-specific classes. In addition to the classes implemented in this library, the modules contain wrappers to the solvers’ native C library functions, useful when implementing a “solver native” usage.


If amplpy is installed, importing the modules add the following functions, which help creating the solver APIs objects and, after solving them, importing them back to AMPL:

  • amplpy.AMPL.exportGurobiModel

  • amplpy.AMPL.exportCplexModel

  • amplpy.AMPL.exportModel(drivername)

  • amplpy.AMPL.importSolution(AMPLModel)