{"id":20919,"library":"amplpy","title":"AMPL Python API","description":"amplpy is the official Python API for AMPL, a powerful algebraic modeling language for optimization. Version 0.16.0 provides a Pythonic interface to define models, solve them with AMPL's solvers, and manipulate results. It is maintained by AMPL Inc. and follows a regular release cadence aligned with AMPL updates.","status":"active","version":"0.16.0","language":"python","source_language":"en","source_url":"https://github.com/ampl/amplpy","tags":["optimization","AMPL","modeling","operations-research"],"install":[{"cmd":"pip install amplpy","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Used for array data handling in data frames and entity values","package":"numpy","optional":true}],"imports":[{"note":"Namespace import unnecessary; direct import is standard","wrong":"import amplpy\namplpy.AMPL()","symbol":"AMPL","correct":"from amplpy import AMPL"},{"note":"AMPL DataFrame is separate from pandas DataFrame; using pandas will cause errors","wrong":"from pandas import DataFrame","symbol":"DataFrame","correct":"from amplpy import DataFrame"},{"note":"","wrong":"","symbol":"Environment","correct":"from amplpy import Environment"}],"quickstart":{"code":"from amplpy import AMPL, DataFrame\nampl = AMPL()\nampl.eval('var x; maximize obj: x; subject to c: x <= 1;')\nampl.solve()\nprint('Objective:', ampl.getValue('obj'))","lang":"python","description":"Create an AMPL instance, evaluate a simple model, solve it, and print the objective value."},"warnings":[{"fix":"Use `Environment(ampl_bin='/path/to/ampl')` and pass to `AMPL(environment=env)`.","message":"In amplpy 0.13.0 and later, the `amplpy.AMPL` constructor no longer accepts `ampl_bin` or `format` arguments; use `Environment` to set AMPL path.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"Ensure all column names in pandas DataFrames are strings before converting to AMPL DataFrame.","message":"When using AMPL DataFrame with pandas DataFrames, the column names may be automatically converted to strings; mixing types can cause silent data loss.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace `getData('x')` with `get_data('x')`.","message":"The method `getData(name)` is deprecated in favor of `get_data(name)` (underscore convention) since version 0.12.0.","severity":"deprecated","affected_versions":">=0.12.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `pip install amplpy` in the correct environment (e.g., virtualenv).","cause":"amplpy is not installed, or installed in a different Python environment.","error":"ModuleNotFoundError: No module named 'amplpy'"},{"fix":"Set the AMPL path via environment variable `AMPLBIN` or pass `Environment(ampl_bin='/path/to/ampl')` to the `AMPL` constructor.","cause":"AMPL is not installed or not in PATH, and amplpy cannot locate the AMPL executable.","error":"RuntimeError: AMPL executable not found. Please set the AMPL path"},{"fix":"Convert column names to strings and ensure data types are basic (int, float, str).","cause":"Using numpy or pandas data types that are not supported by AMPL's C++ interface; often due to using pandas DataFrames with non-string column names.","error":"TypeError: No matching signature found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}