Skip to main content

einheit (Python)

Python bindings for Einheit, a linear programming solver written in Rust. The solver runs as native code inside the package; Python builds the model and reads the result. The package also works as a solver backend for PuLP and Pyomo.

Einheit solves linear programs today. Mixed-integer programming is in development: a branch-and-bound search that races its work across cores. It is not part of a release yet.

Install

pip install einheit

To use Einheit as a PuLP or Pyomo solver, install the matching extra:

pip install "einheit[pulp]"
pip install "einheit[pyomo]"

Requires Python 3.11 or newer. Wheels are published for Linux x86_64, macOS arm64, and Windows x86_64. They include the compiled solver, so no Rust toolchain is needed. There is no source distribution, so pip cannot install Einheit on other platforms yet.

Quick start

import einheit

lp = einheit.parse_mps(open("afiro.mps").read())
sol = einheit.solve(lp)
if sol.is_optimal:
    print(sol.objective)   # -464.7531428571
    print(sol.x)           # primal solution, length lp.num_cols

API

Building a model

Three ways to get an Lp:

import einheit, math

# 1. MPS text
lp = einheit.parse_mps(open("model.mps").read())

# 2. CPLEX / Gurobi LP-format text
lp = einheit.parse_lp(open("model.lp").read())

# 3. Programmatic builder — no file needed
b = einheit.LpBuilder("demo")
b.sense("maximize")                              # default is "minimize"
x = b.add_var("x", 3.0, 0.0, math.inf)          # returns VarRef
y = b.add_var("y", 2.0, 0.0, math.inf)
b.add_constraint("c1", [(x, 1.0), (y, 1.0)], -math.inf, 4.0)
b.add_constraint("c2", [(x, 1.0), (y, 3.0)], -math.inf, 6.0)
lp = b.build()                                   # raises ValueError on bad bounds / refs

Reference

  • parse_mps(text: str) -> Lp — parse an MPS model (raises ValueError on a bad model).
  • parse_lp(text: str) -> Lp — parse a CPLEX / Gurobi LP-format model (raises ValueError on a bad model). Produces the same Lp as parse_mps — the two readers are interchangeable.
  • LpBuilder(name: str = "") -> LpBuilder — programmatic model builder.
    • .sense(sense: str) — "minimize" (default) or "maximize".
    • .objective_offset(offset: float) — constant term added to the objective.
    • .add_var(name, obj, lower, upper) -> VarRef — add a variable; returns an opaque handle.
    • .add_constraint(name, coeffs, lower, upper) — add a ranged row; coeffs is a list of (VarRef, float) pairs.
    • .build() -> Lp — validate and pack; raises ValueError on bad bounds or foreign refs.
  • VarRef — opaque column handle; .index gives the column number.
  • Lp — num_rows, num_cols, nnz, name, col_names, row_names (all read-only).
  • solve(lp, *, max_iters=None, driver=None, presolve=None, edge_weight=None) -> Solution — solve to optimum / infeasible / unbounded. Releases the GIL while the simplex runs. All keyword args default to None (Rust Options::default()); pass explicit values to override: driver ("primal" / "dual"), presolve (True / False), edge_weight ("dantzig" / "steepest"). Raises ValueError on unknown strings.
  • Solution — status ("optimal" | "infeasible" | "unbounded" | "iteration_limit"), is_optimal, objective, x, iterations.

License

MIT License. Copyright (c) 2026 Dennis Cost.

Metadata

Release files for einheit 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for einheit 0.5.0
File Interpreter ABI Platform Actions
einheit-0.5.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for einheit-0.5.0-cp311-abi3-win_amd64.whl
einheit-0.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for einheit-0.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
einheit-0.5.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for einheit-0.5.0-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 3.5 MB

Release files / einheit-0.5.0-cp311-abi3-win_amd64.whl

Download URL einheit-0.5.0-cp311-abi3-win_amd64.whl
Size 1.1 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0669666d8ec93065fda1d190ef3027f2097aec13e4b64b9510768873c72daf46
BLAKE2b-256 checksum
How to use checksums
a74b5507608e45e1a367d6836696e7c8f8120ef6f9da52cd910fa07cf47c614e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / einheit-0.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL einheit-0.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
9a2c9e13fe57ed84f0ca20a2aff42864e220a09461c8729c9f58edb2d3ac5dcf
BLAKE2b-256 checksum
How to use checksums
00ed05ead8019000063d704ab7f10452563f83d303d429ef501d853c8953a6c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / einheit-0.5.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL einheit-0.5.0-cp311-abi3-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ebfc12852b5ab0708f276302e596a2e0ed5c4eaa883d496fb3060b441e9a3c0f
BLAKE2b-256 checksum
How to use checksums
17a1a47db793ba84567e120ad70b44e636c76e7da3082917816f4af7a9677275
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for einheit 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.0 This release

3 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page