skillfed

amplpy

Python API for AMPL

amplpy v0.18.0 75.2K downloads/30d#14,738 on PyPI86
Permissive license BSD-3 Active released

What it is and what it does

amplpy is a Python binding for AMPL, a domain-specific language for mathematical optimization. It lets you express optimization problems—linear, nonlinear, mixed-integer—using natural mathematical syntax within Python, then solve them with industry-standard solvers like Gurobi, HiGHS, or CBC. The library handles model generation and solver communication directly in AMPL's optimized C code, so you get performance without sacrificing readability.

You define models using AMPL's syntax (passed as strings), populate them with data from Python lists, pandas DataFrames, or numpy arrays, call solve(), and extract results back into Python objects. This workflow is especially useful for large-scale optimization where you want the stability and speed of compiled solvers but the flexibility of Python for data preprocessing and post-processing.

Use it for:

  • Portfolio optimization: define variance minimization with weight constraints, pass covariance matrices from pandas, solve with Gurobi.
  • Supply chain planning: model production, inventory, and distribution constraints in AMPL, feed demand forecasts from Python, retrieve optimal schedules.
  • Engineering design: set up nonlinear constraint systems, optimize over continuous or discrete variables, integrate results into a larger Python application.
  • Research and prototyping: quickly iterate on optimization formulations without rewriting solver interfaces for each model variant.
  • Production deployment: use the same AMPL model across Python, C++, or other languages by switching only the API layer.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

amplpy is a Python interface to AMPL, an algebraic modeling language for optimization problems, allowing you to define, solve, and extract results from large-scale linear, nonlinear, and mixed-integer optimization models.

Yes, if you need to solve optimization problems and want a mature, language-agnostic modeling layer. The active maintenance, broad Python version support, and permissive license make it a solid choice. Caveat: you must install a solver separately and obtain an AMPL license (free Community Edition available); this adds setup friction beyond a typical pip install.

Install

amplpy on PyPI

pip

pip install amplpy

uv

uv add amplpy

poetry

poetry add amplpy

Installing amplpy

Before you install

Medium install friction: prebuilt wheels available for Python 3.8–3.14 across macOS, Linux, and Windows, but the package depends on ampltools and requires an AMPL solver installation (HiGHS, CBC, Gurobi, etc.) via a separate module installer. Repository is actively maintained with a recent release.

License in practice

BSD-3 license is permissive; you can use amplpy in commercial and proprietary projects without copyleft obligations, though you must include the license notice.

Quickstart

pip install amplpy
python -m amplpy.modules install highs

from amplpy import AMPL
ampl = AMPL()
ampl.eval("var x >= 0; minimize cost: x;")
ampl.solve(solver="highs")

Requires a solver to be installed via `python -m amplpy.modules install <solver>` (e.g., highs, cbc, gurobi) and a valid AMPL license (free Community Edition available).

Verify before relying

  • Whether ampltools is a compiled dependency that may require build tools on some platforms.
  • Exact memory and CPU overhead when working with very large models or datasets.
  • Whether the free AMPL Community Edition has model size or feature restrictions.

Package facts

License BSD-3 (permissive)
Python support not specified
Install friction medium — platform-specific wheel
Runtime dependencies 1 — ampltools
Maintenance actively maintained — 24 days since the last release
Last repo commit
First released
Downloads 75,216/month — #14,738 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: amplpy-0.18.0-cp310-cp310-macosx_10_9_universal2.whl; amplpy-0.18.0-cp310-cp310-macosx_10_9_x86_64.whl; amplpy-0.18.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; amplpy-0.18.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; amplpy-0.18.0-cp310-cp310-win_amd64.whl; amplpy-0.18.0-cp311-cp311-macosx_10_9_universal2.whl; amplpy-0.18.0-cp311-cp311-macosx_10_9_x86_64.whl; amplpy-0.18.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; amplpy-0.18.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; amplpy-0.18.0-cp311-cp311-win_amd64.whl; amplpy-0.18.0-cp312-cp312-macosx_10_13_universal2.whl; amplpy-0.18.0-cp312-cp312-macosx_10_13_x86_64.whl; amplpy-0.18.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; amplpy-0.18.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; amplpy-0.18.0-cp312-cp312-win_amd64.whl; amplpy-0.18.0-cp313-cp313-macosx_10_13_universal2.whl; amplpy-0.18.0-cp313-cp313-macosx_10_13_x86_64.whl; amplpy-0.18.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; amplpy-0.18.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; amplpy-0.18.0-cp313-cp313-win_amd64.whl

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: POSIXOperating System :: UnixProgramming Language :: CProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Free Threading :: 2 - BetaProgramming Language :: Python :: Implementation :: CPythonTopic :: Scientific/EngineeringTopic :: Software Development

Tags

optimization modeling in PythonAMPL Python interfacemathematical optimization solverlinear programming Pythonmixed-integer optimizationalgebraic modeling languageconstraint optimization
optimizationmathematical-modelingsolver-interface

More Software Development packages