swiglpk 5.0.13


pip install swiglpk

  Latest version

Released: Feb 05, 2026

Project Links

Meta
Author: Nikolaus Sonnenschein

Classifiers

Development Status
  • 5 - Production/Stable

Topic
  • Scientific/Engineering
  • Software Development

Intended Audience
  • Science/Research

Programming Language
  • Python :: 2.7
  • Python :: 3.4

License
  • OSI Approved :: GNU General Public License v3 (GPLv3)

Plain python bindings for the GNU Linear Programming Kit (GLPK)

PyPI License Build Status

Why?

swiglpk is not a high-level wrapper for GLPK (take a look at optlang if you are interested in a python-based mathematical programming language). It just provides plain vanilla swig bindings to the underlying C library. In constrast to other GLPK wrappers for python (e.g. PyGLPK, Python-GLPK, ctypes-glpk, ecyglpki etc.) it is fairly version agnostic: it will try to guess the location of the glpk.h header file (using which glpsol) and then compile the extension for your particular GLPK installation. Furthermore, swiglpk provides binary wheels for all major platforms, which are always up-to-date with the most recent GLPK version (swiglpk versions follow GLPK versioning in the major and minor version digits to emphasize that).

Please show us some love by staring this repo if you find swiglpk useful!

Installation

pip install swiglpk

That’s it. swiglpk comes with binary wheels for Windows, Mac, and Linux. No installation of third-party dependencies necessary.

Example

Running the following (slightly adapted) example from the GLPK manual …

from swiglpk import *

ia = intArray(1+1000); ja = intArray(1+1000);
ar = doubleArray(1+1000);
lp = glp_create_prob();
glp_set_prob_name(lp, "sample");
glp_set_obj_dir(lp, GLP_MAX);
glp_add_rows(lp, 3);
glp_set_row_name(lp, 1, "p");
glp_set_row_bnds(lp, 1, GLP_UP, 0.0, 100.0);
glp_set_row_name(lp, 2, "q");
glp_set_row_bnds(lp, 2, GLP_UP, 0.0, 600.0);
glp_set_row_name(lp, 3, "r");
glp_set_row_bnds(lp, 3, GLP_UP, 0.0, 300.0);
glp_add_cols(lp, 3);
glp_set_col_name(lp, 1, "x1");
glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);
glp_set_obj_coef(lp, 1, 10.0);
glp_set_col_name(lp, 2, "x2");
glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);
glp_set_obj_coef(lp, 2, 6.0);
glp_set_col_name(lp, 3, "x3");
glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);
glp_set_obj_coef(lp, 3, 4.0);
ia[1] = 1; ja[1] = 1; ar[1] = 1.0; # a[1,1] = 1
ia[2] = 1; ja[2] = 2; ar[2] = 1.0; # a[1,2] = 1
ia[3] = 1; ja[3] = 3; ar[3] = 1.0; # a[1,3] = 1
ia[4] = 2; ja[4] = 1; ar[4] = 10.0; # a[2,1] = 10
ia[5] = 3; ja[5] = 1; ar[5] = 2.0; # a[3,1] = 2
ia[6] = 2; ja[6] = 2; ar[6] = 4.0; # a[2,2] = 4
ia[7] = 3; ja[7] = 2; ar[7] = 2.0; # a[3,2] = 2
ia[8] = 2; ja[8] = 3; ar[8] = 5.0; # a[2,3] = 5
ia[9] = 3; ja[9] = 3; ar[9] = 6.0; # a[3,3] = 6
glp_load_matrix(lp, 9, ia, ja, ar);
glp_simplex(lp, None);
Z = glp_get_obj_val(lp);
x1 = glp_get_col_prim(lp, 1);
x2 = glp_get_col_prim(lp, 2);
x3 = glp_get_col_prim(lp, 3);
print("\nZ = %g; x1 = %g; x2 = %g; x3 = %g\n" % (Z, x1, x2, x3))
glp_delete_prob(lp);

… will produce the following output (the example can also be found at examples/example.py):

GLPK Simplex Optimizer, v4.52
3 rows, 3 columns, 9 non-zeros
*     0: obj =   0.000000000e+00  infeas =  0.000e+00 (0)
*     2: obj =   7.333333333e+02  infeas =  0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND

Z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0

Pretty ugly right? Consider using optlang for formulating and solving your optimization problems.

Documentation

You can find documentation on GLPK’s C API here

Development

You still want to install it from source? Then you’ll need to install the following dependencies first.

  • GLPK

  • swig

If you’re on OS X, swig and GLPK can easily be installed with homebrew.

brew install swig glpk

If you’re using ubuntu linux, you can install swig and GLPK using apt-get.

apt-get install glpk-utils libglpk-dev swig

If you’re on Windows, you are on your own (checkout the appveyor.yml config file for directions).

Then clone the repo and run the following.

python setup.py install
5.0.13 Feb 05, 2026
5.0.12 Nov 25, 2024
5.0.10 Nov 10, 2023
5.0.8 Oct 28, 2022
5.0.5 Mar 21, 2022
5.0.4 Jan 11, 2022
5.0.3 Mar 12, 2021
5.0.0 Feb 22, 2021
4.65.1 Jan 09, 2020
4.65.0 Sep 21, 2018
4.64.0b0 Aug 17, 2018
1.5.1 Aug 17, 2018
1.5.0 Aug 14, 2018
1.5.0b0 Aug 14, 2018
1.4.4 Aug 08, 2017
1.4.3 Apr 19, 2017
1.4.1 Feb 20, 2017
1.4.1b2 Feb 20, 2017
1.4.0 Feb 03, 2017
1.4.0b0 Feb 02, 2017
1.3.3 Nov 24, 2016
1.3.3rc2 Nov 24, 2016
1.3.3rc1 Nov 24, 2016
1.3.2rc1 Nov 24, 2016
1.2.22 Aug 02, 2016
1.2.21 Aug 02, 2016
1.2.20 Aug 02, 2016
1.2.19 Jul 28, 2016
1.2.18 Jul 28, 2016
1.2.17 Jul 28, 2016
1.2.16 Jul 28, 2016
1.2.15 Jul 28, 2016
1.2.14 Feb 29, 2016
1.2.13 Feb 26, 2016
1.2.12 Feb 19, 2016
1.0.0 Feb 07, 2015
0.1.0 Jul 29, 2014
4.65.1.win32 Jan 09, 2020
4.65.1.win Jan 09, 2020
4.65.0.win32 Sep 21, 2018
4.65.0.win Sep 21, 2018
4.64.0b.win32 Aug 17, 2018
4.64.0b.win Aug 17, 2018
1.5.1.win32 Aug 17, 2018
1.5.1.win Aug 17, 2018
1.5.0b.win32 Aug 14, 2018
1.5.0b.win Aug 14, 2018
1.5.0.win32 Aug 14, 2018
1.5.0.win Aug 14, 2018
1.4.4.win32 Aug 08, 2017
1.4.4.win Aug 08, 2017
1.4.3.win32 Apr 19, 2017
1.4.3.win Apr 19, 2017
1.4.1b2.win32 Feb 20, 2017
1.4.1b2.win Feb 20, 2017
1.4.1.win32 Feb 20, 2017
1.4.1.win Feb 20, 2017
1.4.0b.win32 Feb 02, 2017
1.4.0b.win Feb 02, 2017
1.4.0.win32 Feb 03, 2017
1.4.0.win Feb 03, 2017
1.3.3rc2.win32 Nov 24, 2016
1.3.3rc2.win Nov 24, 2016
1.3.3.win32 Nov 24, 2016
1.3.3.win Nov 24, 2016
1.3.2rc1.win32 Nov 24, 2016
1.3.2rc1.win Nov 24, 2016

Wheel compatibility matrix

Platform CPython 3.8 CPython 3.9 CPython 3.10 CPython 3.11 CPython 3.12 CPython 3.13 CPython 3.14 CPython (additional flags: t) 3.14
macosx_10_13_x86_64
macosx_10_15_x86_64
macosx_10_9_x86_64
macosx_11_0_arm64
manylinux2014_aarch64
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_x86_64
manylinux_2_28_aarch64
manylinux_2_28_x86_64
win32
win_amd64

Files in release

swiglpk-5.0.13-cp310-cp310-macosx_10_9_x86_64.whl (764.5KiB)
swiglpk-5.0.13-cp310-cp310-macosx_11_0_arm64.whl (746.3KiB)
swiglpk-5.0.13-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2MiB)
swiglpk-5.0.13-cp310-cp310-win32.whl (454.5KiB)
swiglpk-5.0.13-cp310-cp310-win_amd64.whl (567.6KiB)
swiglpk-5.0.13-cp311-cp311-macosx_10_9_x86_64.whl (764.5KiB)
swiglpk-5.0.13-cp311-cp311-macosx_11_0_arm64.whl (746.3KiB)
swiglpk-5.0.13-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3MiB)
swiglpk-5.0.13-cp311-cp311-win32.whl (454.5KiB)
swiglpk-5.0.13-cp311-cp311-win_amd64.whl (567.6KiB)
swiglpk-5.0.13-cp312-cp312-macosx_10_13_x86_64.whl (756.6KiB)
swiglpk-5.0.13-cp312-cp312-macosx_11_0_arm64.whl (746.7KiB)
swiglpk-5.0.13-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3MiB)
swiglpk-5.0.13-cp312-cp312-win32.whl (455.1KiB)
swiglpk-5.0.13-cp312-cp312-win_amd64.whl (567.9KiB)
swiglpk-5.0.13-cp313-cp313-macosx_10_13_x86_64.whl (756.2KiB)
swiglpk-5.0.13-cp313-cp313-macosx_11_0_arm64.whl (746.3KiB)
swiglpk-5.0.13-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3MiB)
swiglpk-5.0.13-cp313-cp313-win32.whl (455.1KiB)
swiglpk-5.0.13-cp313-cp313-win_amd64.whl (567.9KiB)
swiglpk-5.0.13-cp314-cp314-macosx_10_15_x86_64.whl (757.6KiB)
swiglpk-5.0.13-cp314-cp314-macosx_11_0_arm64.whl (746.4KiB)
swiglpk-5.0.13-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.3MiB)
swiglpk-5.0.13-cp314-cp314-win32.whl (466.7KiB)
swiglpk-5.0.13-cp314-cp314-win_amd64.whl (586.3KiB)
swiglpk-5.0.13-cp314-cp314t-macosx_10_15_x86_64.whl (761.2KiB)
swiglpk-5.0.13-cp314-cp314t-macosx_11_0_arm64.whl (748.6KiB)
swiglpk-5.0.13-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2MiB)
swiglpk-5.0.13-cp314-cp314t-win32.whl (472.9KiB)
swiglpk-5.0.13-cp314-cp314t-win_amd64.whl (595.3KiB)
swiglpk-5.0.13-cp38-cp38-macosx_10_9_x86_64.whl (764.3KiB)
swiglpk-5.0.13-cp38-cp38-macosx_11_0_arm64.whl (746.1KiB)
swiglpk-5.0.13-cp38-cp38-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2MiB)
swiglpk-5.0.13-cp38-cp38-win32.whl (454.5KiB)
swiglpk-5.0.13-cp38-cp38-win_amd64.whl (567.5KiB)
swiglpk-5.0.13-cp39-cp39-macosx_10_9_x86_64.whl (764.5KiB)
swiglpk-5.0.13-cp39-cp39-macosx_11_0_arm64.whl (746.3KiB)
swiglpk-5.0.13-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.1MiB)
swiglpk-5.0.13-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.2MiB)
swiglpk-5.0.13-cp39-cp39-win32.whl (454.5KiB)
swiglpk-5.0.13-cp39-cp39-win_amd64.whl (567.6KiB)
swiglpk-5.0.13.tar.gz (38.8KiB)
No dependencies