# Gap AMPL API Python

**URL:** <https://discuss.ampl.com/t/gap-ampl-api-python/789>\
**Category:** Support\
**Created:** [November 2, 2023, 5:42am UTC](https://discuss.ampl.com/t/gap-ampl-api-python/789 "2023-11-02T05:42:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscar\_Romero](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/oscar_romero/32/466_2.png) [@Oscar\_Romero](https://discuss.ampl.com/u/Oscar_Romero)\
**Post date:** [November 2, 2023, 5:42am UTC](https://discuss.ampl.com/t/gap-ampl-api-python/789/1 "2023-11-02T05:42:59Z")

</div>

I need to obtain the gap in AMPL API Python. I know that in AMPL the code is “display z.relmipgap” where z is the name of objective function.  
the information capture is necesary because I export the results to excel.

I’m using gurobi and writed "ampl.option[“gurobi\_options”] = “outlev=1 timelim=150 bestbound=1 return\_mipgap=3"”

I defined “GAP = ampl.get\_option(“relmipgap”)” but whitout success

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [November 2, 2023, 4:48pm UTC](https://discuss.ampl.com/t/gap-ampl-api-python/789/2 "2023-11-02T16:48:54Z")

</div>

Hi @Oscar_Romero,

The value for relmipgap is not returned as an option but as a suffix for the objective. You can retrieve it with `GAP = ampl.get_value("objective_name.relmipgap")` (replacing “objective\_name” by the name of your objective).

---

<div class="post-metadata">

**Author:** ![Oscar\_Romero](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/oscar_romero/32/466_2.png) [@Oscar\_Romero](https://discuss.ampl.com/u/Oscar_Romero)\
**Post date:** [November 20, 2023, 9:16pm UTC](https://discuss.ampl.com/t/gap-ampl-api-python/789/3 "2023-11-20T21:16:50Z")

</div>

Thank you very much, everything worked ok
