gurobipy, the Gurobi Python Interface

The Gurobi Python interface can be used in a number of ways. It is the basis of our Interactive Shell, where it is typically used to work with existing models. It can also be used to write standalone programs that create and solve models, in much the same way that you would use our other language interfaces. The Gurobi distribution includes a Python interpreter and a basic set of Python modules, with gurobipy among them. There are also a number of options for installing gurobipy in your Python environment of choice.

When comparing our Python interface against our other language interfaces, you will find that our Python interface provides a lot more options for building a model. You can work with individual variables and constraints, like you do in other object-oriented interfaces, or you can work with matrices, like you do in our matrix-oriented interfaces. Our Python interface also includes a few higher-level constructs that allow you to build models using a more mathematical syntax, similar to the way you might work with a traditional modeling language.

This section will work through three Python modeling examples. The first will present a Python program that is similar to the C, C++, Java, and C# programs presented in previous sections. The second shows how to build models using matrices. The third demonstrates some of the higher-level modeling capabilities of our Python interface.

This section assumes that you are already familiar with the Python programming language, and that you have read the preceding section on the Gurobi Interactive Shell. If you would like to learn more about the Python language, we recommend that you visit the Python online tutorial.

Important note for AIX users: due to limited Python support on AIX, our AIX port does not include the Interactive Shell or the Python interface. You can use the C, C++, or Java interfaces.

The Python example directory contains a number of examples. We encourage you to browse and modify them in order to become more familiar with the Gurobi Python interface. We also encourage you to read the Gurobi Example Tour for more information.

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.