linopy
Linear optimization with N-D labeled arrays in Python
What it is and what it does
linopy is a Python optimization modeling framework that lets you define linear, integer, mixed-integer, and quadratic programming problems using labeled n-dimensional arrays. It sits between data-handling libraries like xarray and external solvers, allowing you to express optimization constraints and objectives in a way that mirrors your data's natural structure—with coordinates like time, location, or consumer IDs—rather than flattening everything into matrices.
You define variables with bounds and coordinates, build constraints and objectives using arithmetic operations on those variables (with full broadcasting support), and then hand the model off to an external solver of your choice. linopy handles the translation to the solver's format and can import/export models via netCDF. It supports lazy evaluation with dask for large problems and is designed to make the optimization model transparent and easy to modify on the fly.
Use it for:
- Energy system planning: optimize generation and storage across time and regions with coordinate-based constraints.
- Supply chain optimization: define inventory, production, and distribution variables indexed by product, location, and time period.
- Resource allocation: minimize cost or maximize utility subject to constraints on budget, capacity, or demand across labeled dimensions.
- Scheduling problems: model shift assignments or task scheduling using time and agent coordinates with linear constraints.
- Portfolio optimization: construct investment problems with asset and time-period coordinates and quadratic objectives.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
linopy builds linear, integer, and quadratic optimization models using labeled n-dimensional arrays, bridging xarray data structures with external solvers.
Yes. linopy is actively maintained, has low install friction, carries no known vulnerabilities, and offers a genuinely useful abstraction for optimization problems that naturally live in labeled arrays. Install it if you need to build optimization models with xarray-like data structures or if you want to avoid hand-coding matrix construction for multi-dimensional problems. The trade-off is that you must install a solver separately; linopy alone is only the modeling layer.
Install
linopy on PyPI
pip
pip install linopyuv
uv add linopypoetry
poetry add linopyInstalling linopy
Before you install
Low install friction with a pure-Python wheel distribution. Active maintenance with a recent release (21 days old) and ongoing commits. Depends on well-established packages like numpy, scipy, xarray, and dask; no compiled system dependencies required by linopy itself.
License in practice
MIT license (permissive) means you can use, modify, and distribute linopy freely in commercial or private projects with minimal restrictions—only attribution and license inclusion required.
Quickstart
import linopy
m = linopy.Model()
apples = m.add_variables(lower=0, name="apples")
bananas = m.add_variables(lower=0, name="bananas")
m.add_constraints(3 * apples + 2 * bananas >= 8, name="daily_vitamins")
m.objective = apples + bananas
m.solve()
Requires an external solver (CBC, GLPK, HiGHS, SCIP, Gurobi, Xpress, Cplex, MOSEK, COPT, cuPDLPx, or Knitro) to be installed separately; linopy itself is only the modeling layer.
Verify before relying
- Performance comparison claims in the description refer to benchmarks not included in the fact sheet.
- Whether lazy operations with dask scale effectively for very large problems is not quantified.
- Solver selection and configuration details beyond the supported list are not documented in the excerpt.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 11 — numpy, scipy, bottleneck, toolz, numexpr, xarray, dask, polars, tqdm, deprecation, packaging |
| Maintenance | actively maintained — 21 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 134,199/month — #11,485 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: linopy-0.9.0-py3-none-any.whl
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
mipPython MIP models and solves mixed-integer…
copyleft · top 15,000 on PyPI
PuLPPuLP is a linear and mixed-integer programming…
permissive · top 5,000 on PyPI
xarray-einstatsProvides xarray-friendly wrappers around NumPy…
permissive · top 5,000 on PyPI
xarrayxarray adds dimension, coordinate, and…
permissive · top 5,000 on PyPI
optlangOptlang formulates and solves linear,…
permissive · top 15,000 on PyPI
cvxpyCVXPY is a Python modeling language for…
permissive · top 5,000 on PyPI
amplpyamplpy is a Python interface to AMPL, an…
permissive · top 15,000 on PyPI
cobraCOBRApy is a constraint-based modeling package…
copyleft · top 15,000 on PyPI
cvxoptcvxopt is a Python library for solving convex…
unclear · top 5,000 on PyPI
xpressPython interface to the FICO Xpress Optimizer…
unclear · top 15,000 on PyPI