einheit (Python)
Python bindings for Einheit, a racing LP/MIP solver. A thin PyO3 wrapper over the Rust core — the solver runs native; Python just drives it.
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 (raisesValueErroron a bad model).parse_lp(text: str) -> Lp— parse a CPLEX / Gurobi LP-format model (raisesValueErroron a bad model). Produces the sameLpasparse_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;coeffsis a list of(VarRef, float)pairs..build() -> Lp— validate and pack; raisesValueErroron bad bounds or foreign refs.
VarRef— opaque column handle;.indexgives 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 toNone(RustOptions::default()); pass explicit values to override:driver("primal"/"dual"),presolve(True/False),edge_weight("dantzig"/"steepest"). RaisesValueErroron unknown strings.Solution—status("optimal"|"infeasible"|"unbounded"|"iteration_limit"),is_optimal,objective,x,iterations.
Install from a GitHub Release
Pre-built wheels (Linux x86_64, macOS arm64, Windows x86_64) attach to every GitHub Release. No Rust toolchain required — the compiled core is bundled inside the wheel.
# Replace <tag> with the release tag, e.g. v0.1.0.
pip install einheit \
--find-links https://github.com/einheit-solver/einheit/releases/expanded_assets/<tag>
Build from source
Built with maturin (needs a Rust toolchain):
cd crates/einheit-py
uv run maturin develop # build + install into the uv env (editable)
uv run pytest # run the tests
Or from the repo root:
just python-build # editable install into the uv dev env
just python-test # build + run pytest
just python-wheel # build a release wheel into crates/einheit-py/target/wheels/
Metadata
Release files for einheit 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| einheit-0.4.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for einheit-0.4.0-cp311-abi3-win_amd64.whl |
| einheit-0.4.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.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| einheit-0.4.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for einheit-0.4.0-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 2.7 MB
Release files / einheit-0.4.0-cp311-abi3-win_amd64.whl
| Download URL | einheit-0.4.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
be7cd0ea9f84e8ec208e9ee13d6606c3cf77d771cf6ddf632267caa201841410
|
|
BLAKE2b-256 checksum How to use checksums |
2d8ff8fa4b2195a8d9924db1d635dff191b8012b0c94a5eef4db76a91d86f52f
|
| 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.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | einheit-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 896.4 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7f4745e4e6b0cc141d3b8d9ba798f8a452aa42d8e810f79781d202e261147417
|
|
BLAKE2b-256 checksum How to use checksums |
f2a32b57dd529b374418fdab529779e9a8c046c19de8e7dccac7dfda4e7b3686
|
| 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.4.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | einheit-0.4.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 765.3 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
864dbbbfe1428ba14d8424889c45dcbcc10e9e19d316804b447816d0fc963a67
|
|
BLAKE2b-256 checksum How to use checksums |
fd753cfe4253516f2ebb0e0c15e744bc667d7a22d9215e8cbcc1ed1c70efdf03
|
| 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.4.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.