skillfed

lmfit

Least-Squares Minimization with Bounds and Constraints

lmfit v1.3.4 867.3K downloads/30d#4,855 on PyPI
Permissive license BSD-3-Clause AGING released

What it is and what it does

Lmfit wraps scipy's optimization routines to make curve fitting and least-squares minimization more accessible and flexible. Instead of passing raw arrays to an optimizer, you define named Parameters with optional bounds, fixed values, and mathematical constraints linking them together. The library handles the bookkeeping of which parameters vary and which are held constant, so your fitting function stays clean and model-focused rather than optimization-focused.

The package ships with a Model class for common curve-fitting workflows, built-in model functions, and tools to explore confidence intervals and estimate parameter uncertainties even for solvers where scipy doesn't provide them natively. It's built on numpy and scipy, supports multiple optimization algorithms (Levenberg-Marquardt by default, plus Nelder-Mead, differential_evolution, basin-hopping, and others), and is designed for interactive data analysis where you may want to change constraints or fix parameters on the fly.

Use it for:

  • Fit spectral lines or peaks to experimental data with bounds on amplitude, center, and width.
  • Constrain model parameters by mathematical expressions (e.g., force FWHM = width × 2.355) without rewriting the objective function.
  • Estimate parameter uncertainties and correlations after fitting, or explore confidence intervals.
  • Build reusable model functions and combine them for complex multi-peak or multi-component fits.
  • Switch between optimization algorithms without changing your model or parameter setup.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Lmfit provides non-linear least-squares minimization and curve fitting with named, constrained parameters that can be bounded, fixed, or linked by expressions.

Yes. Lmfit is stable, permissively licensed, and widely used for scientific curve fitting. Install friction is low and it has no known vulnerabilities. The 391-day release gap suggests aging maintenance rather than active development, so treat it as a mature tool rather than one receiving frequent feature updates—but that's appropriate for a well-established optimization library. Install if you need flexible, named-parameter fitting with bounds and constraints.

Install

lmfit on PyPI

pip

pip install lmfit

uv

uv add lmfit

poetry

poetry add lmfit

Installing lmfit

Before you install

Low friction: pure Python wheel with five runtime dependencies (numpy, scipy, asteval, uncertainties, dill). Last release 391 days ago marks aging maintenance, but the package is stable and widely used.

License in practice

BSD-3-Clause permissive license allows commercial and private use with minimal restrictions; attribution required.

Quickstart

pip install lmfit

import lmfit
params = lmfit.create_params(amp=1.2, cen={'value': 40, 'vary': False}, wid={'value': 4, 'min': 0})
result = lmfit.minimize(objective_func, params, args=(x_data, y_data))

Requires Python 3.9 or later; scipy and numpy must be installed first as core dependencies.

Verify before relying

  • Whether the package actively accepts contributions or is in maintenance-only mode given the 391-day release gap.
  • Performance characteristics when fitting models with hundreds or thousands of parameters.

Package facts

License BSD-3-Clause (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 5 — asteval, numpy, scipy, uncertainties, dill
Maintenance aging — 391 days since the last release
First released
Downloads 867,327/month — #4,855 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: lmfit-1.3.4-py3-none-any.whl

Keywords: curve-fitting, least-squares minimization

Development Status :: 5 - Production/StableIntended Audience :: Science/ResearchOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Scientific/Engineering

Tags

least squares fittingcurve fitting pythonnon-linear minimizationparameter optimization boundsconstrained curve fittingmodel fitting with uncertaintiesscipy optimization wrapper
curve-fittingoptimizationparameter-constraints

More Scientific/Engineering packages