{"id":24619322,"url":"https://github.com/ampl/amplpy","last_synced_at":"2025-05-16T13:04:50.042Z","repository":{"id":38816658,"uuid":"95500787","full_name":"ampl/amplpy","owner":"ampl","description":"Python API for AMPL","archived":false,"fork":false,"pushed_at":"2025-05-09T12:48:39.000Z","size":3476,"stargazers_count":80,"open_issues_count":1,"forks_count":20,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-09T13:51:36.903Z","etag":null,"topics":["ampl","amplpy","integer-linear-programming","integer-programming","linear-optimization","linear-programming","milp","mip","mixed-integer-optimization","mixed-integer-programming","modeling-language","nonlinear-optimization","nonlinear-programming","optimization","python"],"latest_commit_sha":null,"homepage":"https://amplpy.ampl.com","language":"Cython","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ampl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-06-27T00:22:07.000Z","updated_at":"2025-05-09T12:48:42.000Z","dependencies_parsed_at":"2024-01-26T12:48:22.893Z","dependency_job_id":"2b4f4be2-005f-4229-bd9c-27e927778b14","html_url":"https://github.com/ampl/amplpy","commit_stats":{"total_commits":526,"total_committers":9,"mean_commits":58.44444444444444,"dds":0.04562737642585546,"last_synced_commit":"8b8dd1a6c5d4f62b79bd95e2b6503893ed51a759"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampl%2Famplpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampl%2Famplpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampl%2Famplpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampl%2Famplpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ampl","download_url":"https://codeload.github.com/ampl/amplpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527087,"owners_count":22085918,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ampl","amplpy","integer-linear-programming","integer-programming","linear-optimization","linear-programming","milp","mip","mixed-integer-optimization","mixed-integer-programming","modeling-language","nonlinear-optimization","nonlinear-programming","optimization","python"],"created_at":"2025-01-25T00:28:21.255Z","updated_at":"2025-05-16T13:04:49.995Z","avatar_url":"https://github.com/ampl.png","language":"Cython","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AMPLPY: Python API for AMPL\n\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/amplpy?label=PyPI%20downloads)](https://pypistats.org/packages/amplpy)\n[![Conda](https://img.shields.io/conda/dn/conda-forge/amplpy?label=Conda%20downloads)](https://anaconda.org/conda-forge/amplpy)\n[![Build Status](https://dev.azure.com/ampldev/amplpy/_apis/build/status/ampl.amplpy?branchName=master)](https://dev.azure.com/ampldev/amplpy/_build/latest?definitionId=9\u0026branchName=test)\n[![build-and-test](https://github.com/ampl/amplpy/actions/workflows/build-and-test.yaml/badge.svg)](https://github.com/ampl/amplpy/actions/workflows/build-and-test.yaml)\n\n```python\n# Install Python API for AMPL\n$ python -m pip install amplpy --upgrade\n\n# Install solver modules (e.g., HiGHS, CBC, Gurobi)\n$ python -m amplpy.modules install highs cbc gurobi\n\n# Activate your license (e.g., free https://ampl.com/ce license)\n$ python -m amplpy.modules activate \u003clicense-uuid\u003e\n\n# Import in Python\n$ python\n\u003e\u003e\u003e from amplpy import AMPL\n\u003e\u003e\u003e ampl = AMPL() # instantiate AMPL object\n```\n```python\n# Minimal example:\nfrom amplpy import AMPL\nimport pandas as pd\nampl = AMPL()\nampl.eval(r\"\"\"\n    set A ordered;\n    param S{A, A};\n    param lb default 0;\n    param ub default 1;\n    var w{A} \u003e= lb \u003c= ub;\n    minimize portfolio_variance:\n        sum {i in A, j in A} w[i] * S[i, j] * w[j];\n    s.t. portfolio_weights:\n        sum {i in A} w[i] = 1;\n\"\"\")\ntickers, cov_matrix = # ... pre-process data in Python\nampl.set[\"A\"] = tickers\nampl.param[\"S\"] = pd.DataFrame(cov_matrix, index=tickers, columns=tickers)\nampl.solve(solver=\"gurobi\", gurobi_options=\"outlev=1\")\nassert ampl.solve_result == \"solved\"\nsigma = ampl.get_value(\"sqrt(sum {i in A, j in A} w[i] * S[i, j] * w[j])\")\nprint(f\"Volatility: {sigma*100:.1f}%\")\n# ... post-process solution in Python\n```\n\n[![Hands-On Mathematical Optimization with AMPL in Python](https://portal.ampl.com/dl/ads/mo_book_big.png)](https://ampl.com/mo-book/)\n\n[[Documentation](https://amplpy.readthedocs.io/)] [[AMPL Modules for Python](https://dev.ampl.com/ampl/python/modules.html)] [[AMPL on Streamlit](https://ampl.com/streamlit)] [[AMPL on Google Colab](https://colab.ampl.com/)] [[Community Edition](https://ampl.com/ce)]\n\n`amplpy` is an interface that allows developers to access the features of [AMPL](https://ampl.com) from within Python. For a quick introduction to AMPL see [Quick Introduction to AMPL](https://dev.ampl.com/ampl/introduction.html).\n\nIn the same way that AMPL’s syntax matches naturally the mathematical description of the model, the input and output data matches naturally Python lists, sets, dictionaries, `pandas` and `numpy` objects.\n\nAll model generation and solver interaction is handled directly by AMPL, which leads to great stability and speed; the library just acts as an intermediary, and the added overhead (in terms of memory and CPU usage) depends mostly on how much data is sent and read back from AMPL, the size of the expanded model as such is irrelevant.\n\nWith `amplpy` you can model and solve large scale optimization problems in Python with the performance of heavily optimized C code without losing model readability. The same model can be deployed on applications built on different languages by just switching the API used.\n\n## Documentation\n\n- http://amplpy.ampl.com\n\n## Examples\n\nData can be loaded in various forms:\n- One of which is ``pandas.DataFrame`` objects:\n\n    [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ampl/amplcolab/blob/master/authors/fdabrandao/quick-start/pandasdiet.ipynb)\n- Python lists and dictionaries:\n     \n     [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ampl/amplcolab/blob/master/authors/fdabrandao/quick-start/nativediet.ipynb)\n\nMore notebooks with examples available on the [AMPL Model Colaboratory](https://colab.ampl.com/).\n\n## Repositories\n\n- GitHub Repository: https://github.com/ampl/amplpy\n- PyPI Repository: https://pypi.python.org/pypi/amplpy\n- Conda-Forge: https://anaconda.org/conda-forge/amplpy\n\n## Setup\n\n### PyPI\n\nInstall from the [PyPI repository](https://pypi.python.org/pypi/amplpy):\n\n```\npython -m pip install amplpy\n```\n\n### AMPL Modules for Python\n\n[AMPL and all Solvers are now available as Python Packages](https://dev.ampl.com/ampl/python/modules.html):\n\n- Install Python API for AMPL:\n    ```\n    python -m pip install amplpy --upgrade\n    ```\n\n- Install solver modules (e.g., HiGHS and Gurobi):\n    ```\n    python -m amplpy.modules install highs gurobi\n    ```\n\n- Activate your license (e.g., free [AMPL Community Edition](https://ampl.com/ce) license):\n    ```\n    python -m amplpy.modules activate \u003clicense-uuid\u003e\n    ```\n\n- Import and instantiate in Python:\n    ```\n    $ python\n    \u003e\u003e\u003e from amplpy import AMPL\n    \u003e\u003e\u003e ampl = AMPL() # instantiate AMPL object\n    ```\n\n### Conda\n\nInstall from the [Conda repository](https://anaconda.org/conda-forge/amplpy):\n\n```\nconda install -c conda-forge amplpy\n```\n\n### Air-gapped installation\n\nFor air-gapped installations we recomend the following:\n- Download on another machine the `.whl` file for the corresponding platform and python version from [pypi](https://pypi.org/project/amplpy/#files).\n- Install on the target machine with: `python -m pip install amplpy-version-python_version-*-platform.whl --no-deps`\n\n### Build locally\n\nYou can build and install the package locally as follows:\n```\n$ git clone https://github.com/ampl/amplpy.git \n$ cd amplpy\n$ python dev/updatelib.py\n$ python setup.py build\n$ pip install . --upgrade\n```\n\n## License\n\nBSD-3\n\n***\nCopyright © 2024 AMPL Optimization inc. All rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampl%2Famplpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fampl%2Famplpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampl%2Famplpy/lists"}