Install & Compatibility
Where this runs
tested against v1.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
415MB installed
● package 415MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Baseline
✓ from pybaselines.api import Baseline
✗ from pybaselines import Baseline
The class-based API 'Baseline' was introduced in v1.0.0 and resides in the `pybaselines.api` submodule.
Baseline2D
✓ from pybaselines.api import Baseline2D
For 2D data processing, introduced in v1.1.0.
asls
✓ from pybaselines.whittaker import asls
Example of importing a specific functional algorithm. Most algorithms are in submodules like `whittaker`, `polynomial`, `morphological`, `smooth`.
window
✓ import pybaselines.smooth as smooth_algos
✗ import pybaselines.window as window_algos
The `pybaselines.window` module was deprecated in v0.7.0 and removed in v0.8.0. Its functionality was moved to `pybaselines.smooth`.
This quickstart demonstrates how to use the recommended class-based API (available since v1.0.0) to perform baseline correction using the Asymmetric Least Squares (ASLS) algorithm. It generates synthetic data with a peak and a sloping baseline, then applies the correction to estimate and remove the baseline.
import numpy as np
from pybaselines.api import Baseline
# 1. Generate some example data
x = np.linspace(0, 100, 500)
y_peak = 10 * np.exp(-((x - 50)**2) / 20) # A simple peak
y_baseline = 0.1 * x + 5 # A sloping baseline
y_data = y_peak + y_baseline + np.random.normal(0, 0.5, x.shape)
# 2. Initialize the Baseline object (using the class-based API, recommended for v1.0.0+)
baseline_fitter = Baseline()
# 3. Apply a baseline correction algorithm, e.g., Asymmetric Least Squares (ASLS)
# The first return value is the estimated baseline, the second is a dictionary of parameters
estimated_baseline, params = baseline_fitter.asls(y_data, lam=1e6, p=0.01)
# 4. The corrected signal is the original data minus the estimated baseline
corrected_signal = y_data - estimated_baseline
print("Baseline estimation complete.")
print(f"First 5 original data values: {y_data[:5].round(2)}")
print(f"First 5 estimated baseline values: {estimated_baseline[:5].round(2)}")
print(f"First 5 corrected signal values: {corrected_signal[:5].round(2)}")
Errors
Common errors & fixes
AttributeError: module 'pybaselines' has no attribute 'window'
Attempting to import or access the `window` module, which was deprecated in v0.7.0 and removed in v0.8.0.
fixReplace any usage of `pybaselines.window` with `pybaselines.smooth`. For example, change `from pybaselines.window import imodpoly` to `from pybaselines.smooth import imodpoly`.
TypeError: 'Baseline' object is not callable
Attempting to call the `Baseline` class instance directly like a function, instead of calling one of its method algorithms.
fixEnsure you are calling a specific algorithm method on the `Baseline` instance. For example, `baseliner = Baseline(); baseline, params = baseliner.asls(data)` instead of `baseline, params = baseliner(data)`.
ImportError: cannot import name 'Baseline' from 'pybaselines' (.../site-packages/pybaselines/__init__.py)
Attempting to import the `Baseline` class directly from the top-level `pybaselines` package, or using a version prior to 1.0.0 where the class-based API did not exist.
fixCorrect the import statement to `from pybaselines.api import Baseline`. If you are using an older version, either upgrade to v1.0.0+ or use the functional API (e.g., `from pybaselines.whittaker import asls`).
Upgrade
Version history
1.2.1latest on PyPI · released Aug 10, 2025
Audit
Dependencies
pythonrequiredRequired Python version
numpyrequiredFundamental for numerical operations and array handling.
scipyrequiredUsed for scientific computing, including sparse matrices and optimization.
numbaoptionalOptional dependency for significant performance improvements in some algorithms.
pentapyoptionalOptional dependency for faster banded matrix solvers in Whittaker-smoothing algorithms.