polarobi
Build gurobipy models from polars frames. Columns go from Arrow memory into the Gurobi C API in one call per variable or constraint family, while the model stays fully usable through gurobipy.
import gurobipy as gp
import polars as pl
from polarobi import GurobiFrame as grb
orders = pl.DataFrame(
{
"order": ["o1", "o1", "o2", "o2", "o3"],
"factory": ["f1", "f2", "f1", "f2", "f2"],
"quantity": [40, 40, 25, 25, 60],
"value": [120.0, 100.0, 100.0, 75.0, 120.0],
}
)
capacity = pl.DataFrame({"factory": ["f1", "f2"], "capacity": [50, 80]})
model = gp.Model()
model.ModelSense = gp.GRB.MAXIMIZE
# One binary variable per order and factory, worth the order's value.
x = grb(orders).add_vars(model, by=["order", "factory"], vtype="B", obj="value", name="x")
# Each order is made at most once, and no factory exceeds its capacity.
grb(x).add_constrs(model, by="order", sense="<=", rhs=1.0, coef=1.0, name="assign")
grb(x).add_constrs(
model, capacity, by="factory", sense="<=", rhs="capacity", coef="quantity", name="cap"
)
model.optimize()
print(grb(x).get(model, "X").filter(pl.col("X") > 0.5))
grb(df) is the typed form of polars' df.grb namespace: both do the same, but type checkers only see the first.
See Type Checking for why.
How it works
Model._cmodelholds theGRBmodel*. The native module binds to the Gurobi library that gurobipy already loaded (never a second copy) and checks that both report the same version.- Numeric columns are passed without copying (one concatenation if a column has several chunks). Names are copied, since C needs NUL-terminated strings.
- New columns and rows are registered with gurobipy as
gp.Var(cmodel, i)/gp.Constr(cmodel, i)handles inModel._internal_vars/Model._constrs. That is what keepsgetVars,getVarByName, mixed expressions,remove,copyand friends working. The handles are created in Rust, at about half the cost of a Python loop over gurobipy's handle constructor. - Constraint and term order follow the input frames, so equal inputs build models with equal
Fingerprints.
This relies on private gurobipy attributes (_cmodel, _internal_vars, _livevars, _constrs,
_liveconstrs, _has_pending_deletions). Pin gurobipy to a minor version and keep
tests/test_compat.py in CI.
Layout
src/: the Rust extension (pyo3,pyo3-arrow), built as modulepolarobi._native.python/polarobi/: the Python package with thedf.grbnamespace.
Build with uv sync (maturin backend, see pyproject.toml); run the tests with uv run pytest.
Metadata
Release files for polarobi 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| polarobi-0.1.1.tar.gz | 391.2 kB | Without provenance | Details for polarobi-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polarobi-0.1.1-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details for polarobi-0.1.1-cp314-cp314-win_amd64.whl |
Total release size: 3.1 MB
Release files / polarobi-0.1.1.tar.gz
| Download URL | polarobi-0.1.1.tar.gz |
|---|---|
| Size | 391.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
364d8c85d95245f90570c8c6afa27685cf1e62a3c554763872c6c95668041f18
|
|
BLAKE2b-256 checksum How to use checksums |
92f5a7314f6b396187be4974e365033b1575e00b44b8ee2c2e100541450f55ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / polarobi-0.1.1-cp314-cp314-win_amd64.whl
| Download URL | polarobi-0.1.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2065ee718c016387e52d62b061eea10dc6db1d78aa6078a9d7b59479e63429a2
|
|
BLAKE2b-256 checksum How to use checksums |
f4388773f65fc40ec4e74f56ff25ec7ba531db47f203d1440f06d6ebb6ab5204
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for polarobi 0.1.1
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.