skillfed

apted

APTED algorithm for the Tree Edit Distance

apted v1.0.3 382.0K downloads/30d#7,093 on PyPI102
Permissive license MIT Abandoned released

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 apted

uv

uv add apted

poetry

poetry add apted

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Topic :: Software Development :: Build Tools

Tags

tree edit distancetree similarity comparisonAPTED algorithmtree transformation costtree alignment mappingstructural tree difftree matching algorithm
tree-algorithmsedit-distancedata-structures

More Build Tools packages

Further reading