apted
APTED algorithm for the Tree Edit Distance
What it is and what it does
APTED is a Python port of the state-of-the-art APTED algorithm for computing tree edit distance—the minimum cost of transforming one tree into another. It accepts trees in bracket notation (e.g., {A{B{X}{Y}{F}}{C}}) and outputs both the edit distance value and a mapping showing which nodes correspond between the source and destination trees. Nodes without a mapping are treated as deletions or insertions.
The package supports customization through Config classes, allowing you to define custom tree structures, label comparisons, and operation costs. It can also track edit mappings during execution via meta_chained_config, though this uses more memory. The implementation has no external runtime dependencies, making it straightforward to install and integrate.
Use it for:
- Measure structural similarity between hierarchical documents by computing edit distance on tree representations
- Compare abstract syntax trees to detect structural changes or refactoring between code versions
- Align hierarchical data structures in bioinformatics or phylogenetics where tree comparison is needed
- Detect changes in nested data structures for version control or diff purposes
- Implement tree-based clustering or classification by using edit distance as a similarity metric
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Computes the tree edit distance between two trees using the APTED algorithm, which measures the minimum cost of transforming one tree structure into another, along with node mappings.
Yes, if you need tree edit distance and can accept an abandoned package. The algorithm is well-established and marked Production/Stable with no known vulnerabilities. Install friction is low and the MIT license is unencumbered. However, verify compatibility with your Python version—the last tested versions were 2.7, 3.4, 3.5, and 3.6, and no updates have been released since 2017.
Install
apted on PyPI
pip
pip install apteduv
uv add aptedpoetry
poetry add aptedInstalling apted
Before you install
Install friction is low with no runtime dependencies. However, the package is abandoned—last commit was 2017-11-08 and no updates have been released since.
License in practice
Published under the MIT license, which is permissive and places no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
pip install apted
from apted import APTED, Config
apted = APTED(tree1, tree2, Config())
distance = apted.compute_edit_distance()
mapping = apted.compute_edit_mapping()
Trees must be provided as objects with a 'name' attribute for labels and a 'children' attribute for child nodes, or a custom Config class must be supplied to define tree structure and comparison logic.
Verify before relying
- Whether the package works correctly on Python versions released after 3.6
- Whether bracket notation is the only supported input format or if other tree representations are supported
- Performance characteristics on large trees or production workloads
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 3,201 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 381,978/month — #7,093 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: apted-1.0.3-py3-none-any.whl
Keywords: APTED, TED, tree, edit, distance
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
zssComputes the edit distance between two tree…
unclear · top 15,000 on PyPI
textdistanceComputes distance and similarity between text…
permissive · top 5,000 on PyPI
editdistanceComputes the edit distance (Levenshtein…
permissive · top 5,000 on PyPI
strsimpyImplements a dozen string similarity and…
permissive · top 15,000 on PyPI
edlibEdlib calculates edit distance (Levenshtein…
permissive · top 15,000 on PyPI
intervaltreeA self-balancing interval tree data structure…
permissive · top 5,000 on PyPI
editdistpyComputes Levenshtein and Damerau-Levenshtein…
permissive · top 15,000 on PyPI
python-LevenshteinComputes Levenshtein edit distance, string…
copyleft · top 5,000 on PyPI
fastdtwfastdtw computes approximate Dynamic Time…
permissive · top 15,000 on PyPI
kaldialignComputes edit distance, alignment, and word…
permissive · top 15,000 on PyPI