Tree extensions for SQLAlchemy

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.

https://github.com/ITCase/sqlalchemy_mptt/

  • No features for querying
  • Injects fields like parent_id, children into the model by itself, without allowing customization.
  • It’s rebuild() is not able to init a tree from scratch.

https://sqlalchemy-orm-tree.readthedocs.org/

  • Integrating into the class-based ORM mapper is messy (pr accepted)
  • No rebuild() feature at all (pr accepted)
  • 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.

https://bitbucket.org/angri/sqlamp/

  • Seems to have a working rebuild()
  • 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 move() methods.

sqlamp and 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s