{"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,"search_vec":"'0.16.0':20 'algebra':14 'align':49 'ampl':1,11,31,41,51,54 'amplpi':4 'api':3,9 'cadenc':48 'defin':26 'follow':44 'inc':42 'interfac':24 'languag':16 'maintain':39 'manipul':35 'model':15,27,55 'offici':7 'oper':57 'operations-research':56 'optim':18,53 'power':13 'provid':21 'python':2,8,23 'regular':46 'releas':47 'research':58 'result':36 'solv':28 'solver':33 'updat':52 'version':19","created_at":"2026-04-27T16:57:08.187218+00:00","updated_at":"2026-04-27T16:57:08.187218+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.16.1","cli_name":"amplpy","cli_version":"sh: 1: amplpy: not found","type":"library","homepage":"http://ampl.com/","github":"https://github.com/ampl/amplpy","docs":null,"changelog":null,"pypi":"https://pypi.org/project/amplpy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","workflow"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}