skillfed

linopy

Linear optimization with N-D labeled arrays in Python

linopy v0.9.0 134.2K downloads/30d#11,485 on PyPI253
Permissive license Active released

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 linopy

uv

uv add linopy

poetry

poetry add linopy

Installing 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

Development Status :: 3 - AlphaEnvironment :: ConsoleIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Typing :: Typed

Tags

linear programming pythonoptimization with xarrayinteger programming solverconstraint optimization arraysmixed-integer programmingquadratic programming pythonoptimization labeled variables
optimizationlinear-programmingxarray-native

More Mathematics packages