dtaidistance
Distance measures for time series (Dynamic Time Warping, fast C implementation)
What it is and what it does
dtaidistance is a library for computing distance measures between time series, centered on Dynamic Time Warping (DTW) and related algorithms. It offers a pure Python implementation and a fast C implementation (with Cython as the build-time dependency). The library is designed to work seamlessly with NumPy and Pandas while avoiding unnecessary data copies.
The package supports a range of DTW variants and optimizations: windowed alignment, pruning strategies, multi-dimensional sequences, barycenter averaging for clustering, and subsequence search. It can compute distances between pairs of series, full distance matrices across sets of series, or partial blocks for distributed computation. The C implementation includes parallelization via OpenMP when available.
Use it for:
- Measure similarity between sensor time series or financial price sequences to detect anomalies or patterns.
- Build distance matrices for time series clustering using hierarchical or other clustering methods.
- Align and compare sequences of different lengths in speech recognition, gesture analysis, or bioinformatics.
- Accelerate large-scale time series comparisons using the fast C backend with optional pruning.
- Compute warping paths and visualize alignment between two time series for exploratory analysis.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Computes distance measures between time series using Dynamic Time Warping (DTW) and related algorithms, with both pure Python and optimized C implementations.
Yes. dtaidistance is actively maintained, has no known vulnerabilities, and offers a well-tested implementation of DTW with both accessibility (pure Python) and performance (C with OpenMP). The Apache-2.0 license is permissive. Install friction is moderate due to C compilation, but pre-built wheels for Python 3.11–3.14 on major platforms mitigate this. Suitable for time series analysis, clustering, and similarity tasks.
Install
dtaidistance on PyPI
pip
pip install dtaidistanceuv
uv add dtaidistancepoetry
poetry add dtaidistanceInstalling dtaidistance
Before you install
Medium install friction due to C compilation, but pre-built wheels cover modern Python versions (3.11–3.14) and major platforms. Last release was 183 days ago with active repository maintenance and 1241 stars.
License in practice
Licensed under Apache-2.0 (permissive), allowing commercial and private use with minimal restrictions.
Quickstart
pip install dtaidistance
from dtaidistance import dtw
import numpy as np
s1 = np.array([0.0, 0, 1, 2, 1, 0, 1, 0, 0])
s2 = np.array([0.0, 1, 2, 0, 0, 0, 0, 0, 0])
d = dtw.distance_fast(s1, s2)
Requires numpy at runtime; C implementation benefits from OpenMP but falls back to pure Python if unavailable.
Verify before relying
- Whether the C implementation is automatically selected or requires explicit configuration on all platforms.
- Performance scaling characteristics for very large time series or high-dimensional data.
- Compatibility with recent versions of scipy for clustering workflows mentioned in the description.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 1 — numpy |
| Maintenance | actively maintained — 183 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 138,728/month — #11,319 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dtaidistance-2.4.0-cp311-cp311-macosx_10_9_universal2.whl; dtaidistance-2.4.0-cp311-cp311-macosx_15_0_arm64.whl; dtaidistance-2.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtaidistance-2.4.0-cp311-cp311-win_amd64.whl; dtaidistance-2.4.0-cp312-cp312-macosx_10_13_universal2.whl; dtaidistance-2.4.0-cp312-cp312-macosx_11_0_arm64.whl; dtaidistance-2.4.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtaidistance-2.4.0-cp312-cp312-win_amd64.whl; dtaidistance-2.4.0-cp313-cp313-macosx_10_13_universal2.whl; dtaidistance-2.4.0-cp313-cp313-macosx_15_0_arm64.whl; dtaidistance-2.4.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtaidistance-2.4.0-cp313-cp313-win_amd64.whl; dtaidistance-2.4.0-cp314-cp314-macosx_10_15_universal2.whl; dtaidistance-2.4.0-cp314-cp314-macosx_26_0_arm64.whl; dtaidistance-2.4.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtaidistance-2.4.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dtaidistance-2.4.0-cp314-cp314-win_amd64.whl
Keywords: dtw, time series, dynamic time warping, distance
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
dtw-pythonComputes Dynamic Time Warping alignments…
copyleft · 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
stumpySTUMPY computes the matrix profile for time…
permissive · top 15,000 on PyPI
DistanceComputes distance metrics (Levenshtein,…
copyleft · top 15,000 on PyPI
strsimpyImplements a dozen string similarity and…
permissive · top 15,000 on PyPI
textdistanceComputes distance and similarity between text…
permissive · top 5,000 on PyPI
pylcsComputes longest common subsequence, longest…
permissive · top 15,000 on PyPI
fastclusterPerforms fast hierarchical agglomerative…
copyleft · top 15,000 on PyPI
simdkalmanImplements vectorized Kalman filters that run…
permissive · top 15,000 on PyPI