ampl-python

A specialist guide for using amplpy, the Python interface to AMPL, in applications and data workflows. It connects Python code, AMPL model files, data libraries, solvers, and optimization results.

In plain words
What is it for?
Use it to write or refactor Python scripts, notebooks, FastAPI services, and data pipelines that load AMPL models, configure solvers, run verified solves, and read results.
Why use it?
It helps keep mathematical model structure separate from Python data handling and application logic. It also gives patterns for installation, solver setup, notebooks, services, and result extraction.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/marcos-dv/ampl-agents/ampl-python
Any agent
npx skills add marcos-dv/ampl-agents --skill ampl-python
Clone the repo
git clone --depth 1 https://github.com/marcos-dv/ampl-agents

Made for: Claude Code, Codex.

Per session 75 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,822 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00075 $0.03822
Opus 5 $0.00037 $0.01911
Sonnet 5 $0.00015 $0.00764
Haiku 4.5 $0.00007 $0.00382

Measured 2d ago against content hash 5aace1338dce, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ampl-python scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

IF you have internet access (WebFetch, browser, or curl):
skills/ampl-python/SKILL.md · 498 lines

How it starts

The opening of the file, as written. The whole thing — 498 lines — stays where its author put it; the contents beside it link to each section on GitHub.

AMPL Python (amplpy) Skill

Always-on constraints (verified solve, model structure, session hygiene) live in rules/ and apply whenever this skill is active.

Mission

You write correct, maintainable amplpy code that drives AMPL models. You know the amplpy API, official best practices, and Colab/MO-Book workflow patterns. You keep model structure in .mod files, use Python for data, orchestration, and results, and always verify solves.

You are not a general Python agent — optimization and AMPL session semantics come first.


Code examples convention

This skill is amplpy-first. Every operational pattern shows Preferred: amplpy then Pure AMPL for the same action (solve, options, queries, IIS). Model structure belongs in model.mod.


AMPL installation

From https://amplpy.ampl.com/en/latest/getting-started.html and https://dev.ampl.com/ampl/python/modules.html.

python -m pip install amplpy --upgrade
python -m amplpy.modules install highs gurobi xpress
python -m amplpy.modules activate <license-uuid>   # https://ampl.com/ce
python -m amplpy.modules run ampl -vvq
from amplpy import AMPL
ampl = AMPL()

Colab:

%pip install -q amplpy
from amplpy import AMPL, ampl_notebook
ampl = ampl_notebook(
    modules=["gurobi", "highs", "xpress"],
    license_uuid="default",
)

Ensure deployed code documents required modules and license UUID source (env var, not committed secrets).


Solver classification (commercial vs open-source)

Sources: https://dev.ampl.com/solvers/index.html , https://dev.ampl.com/ampl/python/modules.html

Open-source modules

Module Solvers Use
highs HiGHS LP, MILP
cbc CBC MILP
coin CBC, Couenne, Ipopt, Bonmin MIP, MINLP, NLP
open All OSS MIP, MINLP, NLP
scip SCIP MIP
gcg GCG Decomposition
gokestrel NEOS Kestrel Remote solvers (Colab)

Read the full file on GitHub · 498 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 498 lines · 75 tokens per session scan A 5aace1338dce

Subscribe to this mod's changes

ampl-python is a skill published in the GitHub repository marcos-dv/ampl-agents (10 stars, last pushed 11d ago), licensed MIT. It adds 75 tokens to every session and 3,822 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

jupyter-notebook

Use when the user asks to create, scaffold, or edit Jupyter notebooks (.ipynb) for experiments, explorations, or tutorials; prefer the bundled templates and run the helper script newnotebook.py to generate a clean starting notebook.

microsoft/ai-agents-for-beginners · 57 tokens

cuopt-routing-api-python

Vehicle routing (VRP, TSP, PDP) with cuOpt — Python API only. Use when the user is building or solving routing in Python.

NVIDIA/skills · 37 tokens

manimce-best-practices

Trigger when: (1) User mentions "manim" or "Manim Community" or "ManimCE", (2) Code contains from manim import , (3) User runs manim CLI commands, (4) Working with Scene, MathTex, Create(), or ManimCE-specific classes. Best practices for Manim Community Edition - the community-maintained Python animation engine.…

calesthio/OpenMontage · 149 tokens

manimgl-best-practices

Trigger when: (1) User mentions "manimgl" or "ManimGL" or "3b1b manim", (2) Code contains from manimlib import , (3) User runs manimgl CLI commands, (4) Working with InteractiveScene, self.frame, self.embed(), ShowCreation(), or ManimGL-specific patterns. Best practices for ManimGL (Grant Sanderson's 3Blue1Brown…

calesthio/OpenMontage · 167 tokens

cupynumeric-install

Install and verify cuPyNumeric for Python — requirements, commands, verification. Source builds are out of scope.

NVIDIA/skills · 27 tokens

telegram-patterns

Telegram-specific patterns and Telethon library usage.

leshchenko1979/fast-mcp-telegram · 12 tokens