dtw-python
A comprehensive implementation of dynamic time warping (DTW) algorithms.
What it is and what it does
dtw-python is a comprehensive implementation of Dynamic Time Warping algorithms for computing optimal alignments between time series. It measures how much temporal stretching or compression is needed to map one sequence onto another, outputting both the cumulative distance and the warping function (alignment path) itself. The package is widely used for time series classification, clustering, and pattern matching in domains like econometrics, chemistry, and bioinformatics.
The implementation supports arbitrary local constraints (symmetric, asymmetric, slope-limited step patterns) and global windowing constraints (Sakoe-Chiba band, Itakura parallelogram), partial matches (open-begin, open-end, substring), and proper normalization. It wraps fast native C code and depends on numpy and scipy for numerical operations. The package is a faithful Python port of R's established DTW package.
Use it for:
- Classify or cluster financial time series (stock prices, economic indicators) by measuring temporal similarity.
- Match speech or audio signals with different playback speeds or durations for speaker recognition or phoneme alignment.
- Align medical time series (ECG, EEG, rehabilitation motion data) to detect patterns despite temporal variations.
- Compare DNA or protein sequences with variable-length insertions/deletions in bioinformatics workflows.
- Detect anomalies in sensor data by computing DTW distance to a reference normal pattern.
- Perform real-time sequence matching with open-end constraints for streaming or incomplete time series.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Computes Dynamic Time Warping alignments between time series, measuring optimal temporal correspondence and cumulative distance with support for windowing and step-pattern constraints.
Yes, if you need time series alignment or distance computation. Active maintenance, no known vulnerabilities, broad Python version support (3.9–3.13), and prebuilt wheels minimize friction. GPL-3.0-or-later copyleft is a blocker only if you cannot open-source your code. The package is production-stable and widely cited in academic literature.
Install
dtw-python on PyPI
pip
pip install dtw-pythonuv
uv add dtw-pythonpoetry
poetry add dtw-pythonInstalling dtw-python
Before you install
Medium install friction due to compiled wheels; prebuilt binaries available for Python 3.9–3.13 on macOS (x86_64, arm64), Linux (x86_64, aarch64), and Windows. Actively maintained with recent releases.
License in practice
GPL-3.0-or-later copyleft license; use in proprietary software requires either licensing negotiation or release of your own code under GPL-3.0 or later.
Quickstart
import numpy as np
from dtw import dtw
query = np.array([1, 2, 3, 4, 5])
reference = np.array([1, 2, 2, 3, 4, 5])
dist, cost_matrix, acc_cost_matrix, path = dtw(query, reference)
Requires numpy and scipy; Python >= 3.9.
Verify before relying
- Performance characteristics (speed, memory usage) for typical time series lengths and multivariate data.
- Availability and quality of visualization/plotting functions mentioned in description.
- Whether all Rabiner-Juang, Sakoe-Chiba, and Rabiner-Myers step patterns are fully implemented.
Package facts
| License | GPL-3.0-or-later (copyleft) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 2 — numpy, scipy |
| Maintenance | actively maintained — 63 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 250,950/month — #8,609 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dtw_python-1.7.5-cp310-cp310-macosx_10_9_x86_64.whl; dtw_python-1.7.5-cp310-cp310-macosx_11_0_arm64.whl; dtw_python-1.7.5-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; dtw_python-1.7.5-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtw_python-1.7.5-cp310-cp310-win_amd64.whl; dtw_python-1.7.5-cp311-cp311-macosx_10_9_x86_64.whl; dtw_python-1.7.5-cp311-cp311-macosx_11_0_arm64.whl; dtw_python-1.7.5-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; dtw_python-1.7.5-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtw_python-1.7.5-cp311-cp311-win_amd64.whl; dtw_python-1.7.5-cp312-cp312-macosx_10_13_x86_64.whl; dtw_python-1.7.5-cp312-cp312-macosx_11_0_arm64.whl; dtw_python-1.7.5-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; dtw_python-1.7.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtw_python-1.7.5-cp312-cp312-win_amd64.whl; dtw_python-1.7.5-cp313-cp313-macosx_10_13_x86_64.whl; dtw_python-1.7.5-cp313-cp313-macosx_11_0_arm64.whl; dtw_python-1.7.5-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; dtw_python-1.7.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtw_python-1.7.5-cp313-cp313-win_amd64.whl
Keywords: timeseries, alignment
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
dtaidistanceComputes distance measures between time series…
permissive · top 15,000 on PyPI
fastdtwfastdtw computes approximate Dynamic Time…
permissive · top 15,000 on PyPI
tslearntslearn provides machine learning algorithms…
permissive · top 15,000 on PyPI
pytsPyts provides time series classification…
permissive · top 15,000 on PyPI
tsfreshAutomatically extracts hundreds of time-series…
permissive · top 15,000 on PyPI
dartsDarts provides forecasting and anomaly…
permissive · top 15,000 on PyPI
pypotsPyPOTS provides machine learning algorithms for…
permissive · top 15,000 on PyPI
lttbDownsamples time series data using the…
permissive · top 15,000 on PyPI
textdistanceComputes distance and similarity between text…
permissive · top 5,000 on PyPI
kaldialignComputes edit distance, alignment, and word…
permissive · top 15,000 on PyPI