skillfed

swiglpk

swiglpk - Simple swig bindings for the GNU Linear Programming Kit

swiglpk v5.0.13 89.9K downloads/30d#13,627 on PyPI30
Copyleft license GPL v3 Active released

What it is and what it does

swiglpk is a thin, low-level wrapper around GLPK's C API generated by SWIG. It exposes the full C interface directly to Python without abstraction, allowing you to call GLPK functions like glp_create_prob(), glp_simplex(), and glp_get_obj_val() almost exactly as you would in C. This means you work with raw arrays, manual memory management, and C-style function calls—it is not a high-level mathematical programming language.

The package is useful when you need direct access to GLPK's capabilities or when you are building a higher-level abstraction on top of it. It ships with prebuilt wheels for all major platforms and Python versions, so installation typically requires only pip install with no compilation step. The trade-off is that the API is verbose and low-level; for most users, a wrapper like optlang is recommended for cleaner, more Pythonic problem formulation.

Use it for:

  • Solve linear programming (LP) and mixed-integer programming (MIP) problems where you need direct control over the underlying GLPK solver.
  • Build a domain-specific optimization framework or mathematical modeling language on top of GLPK's C API.
  • Port existing C/C++ GLPK code to Python while keeping the same algorithmic structure and function calls.
  • Integrate GLPK into a scientific computing pipeline where other components also use low-level C bindings.
  • Access GLPK features or tuning parameters not exposed by higher-level Python wrappers.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

swiglpk provides direct Python bindings to the GNU Linear Programming Kit (GLPK) C library, enabling you to formulate and solve linear and mixed-integer optimization problems from Python code.

Yes, if you need direct GLPK access and accept GPL v3 licensing. The package is actively maintained, has no known vulnerabilities, and installs cleanly via prebuilt wheels. However, if you want a Pythonic API for formulating optimization problems, use optlang or another high-level wrapper instead; swiglpk is intentionally low-level and verbose. Proprietary projects cannot use it due to GPL v3 copyleft.

Install

swiglpk on PyPI

pip

pip install swiglpk

uv

uv add swiglpk

poetry

poetry add swiglpk

Installing swiglpk

Before you install

Installation is straightforward via pip with prebuilt wheels for Windows, macOS, and Linux across multiple Python versions (3.10–3.13 supported in current release). No compilation or external dependencies required at install time. Repository is actively maintained with recent commits.

License in practice

Licensed under GPL v3 (copyleft). Any code that links swiglpk must be distributed under a compatible open-source license; proprietary or closed-source projects cannot use it without negotiating alternative licensing.

Quickstart

pip install swiglpk

from swiglpk import *
lp = glp_create_prob()
glp_set_prob_name(lp, "example")
glp_set_obj_dir(lp, GLP_MAX)
glp_add_rows(lp, 1)
glp_add_cols(lp, 1)
glp_simplex(lp, None)
Z = glp_get_obj_val(lp)
glp_delete_prob(lp)

GLPK C library must be installed on the system; binary wheels bundle it, but source builds require GLPK headers and swig installed separately.

Verify before relying

  • Whether binary wheels include a bundled GLPK library or assume system installation
  • Exact Python version range supported (classifiers list 2.7 and 3.4, but wheels show 3.10–3.13)
  • Performance characteristics compared to higher-level wrappers like optlang

Package facts

License GPL v3 (copyleft)
Python support not specified
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 190 days since the last release
Last repo commit
First released
Downloads 89,948/month — #13,627 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: swiglpk-5.0.13-cp310-cp310-macosx_10_9_x86_64.whl; swiglpk-5.0.13-cp310-cp310-macosx_11_0_arm64.whl; swiglpk-5.0.13-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; swiglpk-5.0.13-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; swiglpk-5.0.13-cp310-cp310-win32.whl; swiglpk-5.0.13-cp310-cp310-win_amd64.whl; swiglpk-5.0.13-cp311-cp311-macosx_10_9_x86_64.whl; swiglpk-5.0.13-cp311-cp311-macosx_11_0_arm64.whl; swiglpk-5.0.13-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; swiglpk-5.0.13-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; swiglpk-5.0.13-cp311-cp311-win32.whl; swiglpk-5.0.13-cp311-cp311-win_amd64.whl; swiglpk-5.0.13-cp312-cp312-macosx_10_13_x86_64.whl; swiglpk-5.0.13-cp312-cp312-macosx_11_0_arm64.whl; swiglpk-5.0.13-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; swiglpk-5.0.13-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; swiglpk-5.0.13-cp312-cp312-win32.whl; swiglpk-5.0.13-cp312-cp312-win_amd64.whl; swiglpk-5.0.13-cp313-cp313-macosx_10_13_x86_64.whl; swiglpk-5.0.13-cp313-cp313-macosx_11_0_arm64.whl

Keywords: optimization, swig, glpk

Development Status :: 5 - Production/StableIntended Audience :: Science/ResearchLicense :: OSI Approved :: GNU General Public License v3 (GPLv3)Programming Language :: Python :: 2.7Programming Language :: Python :: 3.4Topic :: Scientific/EngineeringTopic :: Software Development

Tags

linear programming solver pythonglpk python bindingsoptimization library pythoninteger programming pythonsimplex solver pythonconstraint optimizationmathematical programming
optimizationlinear-programmingglpk-bindings

More Software Development packages