--- id: lmfit version: "1.3.4" license: BSD-3-Clause license_treatment: permissive maintenance: aging --- # lmfit — Least-Squares Minimization with Bounds and Constraints License: permissive · Maintenance: aging · Downloads: 867.3K/mo ## 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 above — 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 pip install lmfit uv add lmfit 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_current - Install friction: low - Maintenance: aging - Downloads: 867.3K/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags least squares fitting, curve fitting python, non-linear minimization, parameter optimization bounds, constrained curve fitting, model fitting with uncertainties, scipy optimization wrapper, curve-fitting, optimization, parameter-constraints [View on SkillFed](https://skillfed.io/packages/lmfit) · [View on PyPI](https://pypi.org/project/lmfit/)