I recently needed a performant way to manage a tree, meaning using MPTT, nested sets etc.
I looked at the following libraries, which integrate with SQLAlchemy. These are my notes, some of which seem to be outdated now.
No features for querying
- Injects fields like
childreninto the model by itself, without allowing customization.
rebuild()is not able to init a tree from scratch.
Integrating into the class-based ORM mapper is messy(pr accepted) No(pr accepted)
rebuild()feature at all
- Has bugs when used with ORM attributes are diverging from table column names
- BIG PLUS: can detect and handle tree moves if attributes on an existing node change.
- Does not support keeping a sort order around.
- Seems to have a working
- Can sort of integrate with the class-based ORM mapper setup (although it seems it would need to be globally)
tree_recursive_iterator()for querying a tree.
- To move a subtree, we need to call special
sqlalchemy-orm-tree seem to share a lot of ideas/APIs.
sqlamp seems to be the most most stable / actively developed, although
sqlalchemy-orm-tree makes a good impression, too, and the tree move detection is so helpful that I decided to go with it.