{"id":13502175,"url":"https://github.com/uralbash/sqlalchemy_mptt","last_synced_at":"2025-12-26T08:34:16.711Z","repository":{"id":16098158,"uuid":"18843025","full_name":"uralbash/sqlalchemy_mptt","owner":"uralbash","description":"SQLAlchemy nested sets mixin (MPTT)","archived":false,"fork":false,"pushed_at":"2025-11-21T01:24:55.000Z","size":473,"stargazers_count":198,"open_issues_count":13,"forks_count":33,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-11-27T22:19:05.850Z","etag":null,"topics":["mptt","nested-set","python","sqlalchemy"],"latest_commit_sha":null,"homepage":"http://sqlalchemy-mptt.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uralbash.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":"docs/CONTRIBUTING.rst","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-04-16T14:38:44.000Z","updated_at":"2025-11-21T01:24:54.000Z","dependencies_parsed_at":"2024-04-10T00:39:30.661Z","dependency_job_id":"94518957-aa18-4444-8495-0a3fed2c93b5","html_url":"https://github.com/uralbash/sqlalchemy_mptt","commit_stats":{"total_commits":232,"total_committers":15,"mean_commits":"15.466666666666667","dds":0.2456896551724138,"last_synced_commit":"6b751fb95ad6b0a9eb026c0a798cd9f81c475af4"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/uralbash/sqlalchemy_mptt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uralbash%2Fsqlalchemy_mptt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uralbash%2Fsqlalchemy_mptt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uralbash%2Fsqlalchemy_mptt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uralbash%2Fsqlalchemy_mptt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uralbash","download_url":"https://codeload.github.com/uralbash/sqlalchemy_mptt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uralbash%2Fsqlalchemy_mptt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28050355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mptt","nested-set","python","sqlalchemy"],"created_at":"2024-07-31T22:02:04.827Z","updated_at":"2025-12-26T08:34:16.702Z","avatar_url":"https://github.com/uralbash.png","language":"Python","readme":"|PyPI Version| |PyPI Downloads| |PyPI Python Versions|\n|Build Status| |Coverage Status|\n\nLibrary for implementing Modified Preorder Tree Traversal with your\nSQLAlchemy Models and working with trees of Model instances, like\ndjango-mptt. Docs http://sqlalchemy-mptt.readthedocs.io/\n\n.. image:: https://cdn.rawgit.com/uralbash/sqlalchemy_mptt/master/docs/img/2_sqlalchemy_mptt_traversal.svg\n   :alt: Nested sets traversal\n   :width: 800px\n\nThe nested set model is a particular technique for representing nested\nsets (also known as trees or hierarchies) in relational databases.\n\nInstalling\n----------\n\nInstall from github:\n\n.. code-block:: bash\n\n    pip install git+http://github.com/uralbash/sqlalchemy_mptt.git\n\nPyPi:\n\n.. code-block:: bash\n\n    pip install sqlalchemy_mptt\n\nSource:\n\n.. code-block:: bash\n\n    pip install -e .\n\nUsage\n-----\n\nAdd mixin to model\n\n.. code-block:: python\n\n    from sqlalchemy import Column, Integer, Boolean\n    from sqlalchemy.ext.declarative import declarative_base\n\n    from sqlalchemy_mptt.mixins import BaseNestedSets\n\n    Base = declarative_base()\n\n\n    class Tree(Base, BaseNestedSets):\n        __tablename__ = \"tree\"\n\n        id = Column(Integer, primary_key=True)\n        visible = Column(Boolean)\n\n        def __repr__(self):\n            return \"\u003cNode (%s)\u003e\" % self.id\n\nNow you can add, move and delete obj!\n\nInsert node\n-----------\n\n.. code-block:: python\n\n    node = Tree(parent_id=6)\n    session.add(node)\n\n::\n\n            level           Nested sets example\n            1                    1(1)22\n                    _______________|___________________\n                   |               |                   |\n            2    2(2)5           6(4)11             12(7)21\n                   |               ^                   ^\n            3    3(3)4       7(5)8   9(6)10    13(8)16   17(10)20\n                                                  |          |\n            4                                  14(9)15   18(11)19\n\n            level     Insert node with parent_id == 6\n            1                    1(1)24\n                    _______________|_________________\n                   |               |                 |\n            2    2(2)5           6(4)13           14(7)23\n                   |           ____|____          ___|____\n                   |          |         |        |        |\n            3    3(3)4      7(5)8    9(6)12  15(8)18   19(10)22\n                                       |        |         |\n            4                      10(23)11  16(9)17  20(11)21\n\nDelete node\n-----------\n\n.. code:: python\n\n    node = session.query(Tree).filter(Tree.id == 4).one()\n    session.delete(node)\n\n::\n\n            level           Nested sets example\n            1                    1(1)22\n                    _______________|___________________\n                   |               |                   |\n            2    2(2)5           6(4)11             12(7)21\n                   |               ^                   ^\n            3    3(3)4       7(5)8   9(6)10    13(8)16   17(10)20\n                                                  |          |\n            4                                  14(9)15   18(11)19\n\n            level         Delete node == 4\n            1                    1(1)16\n                    _______________|_____\n                   |                     |\n            2    2(2)5                 6(7)15\n                   |                     ^\n            3    3(3)4            7(8)10   11(10)14\n                                    |          |\n            4                     8(9)9    12(11)13\n\nUpdate node\n-----------\n\n.. code:: python\n\n    node = session.query(Tree).filter(Tree.id == 8).one()\n    node.parent_id = 5\n    session.add(node)\n\n::\n\n            level           Nested sets example\n                1                    1(1)22\n                        _______________|___________________\n                       |               |                   |\n                2    2(2)5           6(4)11             12(7)21\n                       |               ^                   ^\n                3    3(3)4       7(5)8   9(6)10    13(8)16   17(10)20\n                                                      |          |\n                4                                  14(9)15   18(11)19\n\n            level               Move 8 - \u003e 5\n                1                     1(1)22\n                         _______________|__________________\n                        |               |                  |\n                2     2(2)5           6(4)15            16(7)21\n                        |               ^                  |\n                3     3(3)4      7(5)12   13(6)14      17(10)20\n                                   |                        |\n                4                8(8)11                18(11)19\n                                   |\n                5                9(9)10\n\nMove node (support multitree)\n-----------------------------\n\n.. figure:: https://cdn.rawgit.com/uralbash/sqlalchemy_mptt/master/docs/img/3_sqlalchemy_mptt_multitree.svg\n   :alt: Nested sets multitree\n   :width: 600px\n\n   Nested sets multitree\n\nMove inside\n\n.. code:: python\n\n    node = session.query(Tree).filter(Tree.id == 4).one()\n    node.move_inside(\"15\")\n\n::\n\n                     4 -\u003e 15\n            level           Nested sets tree1\n            1                    1(1)16\n                    _______________|_____________________\n                   |                                     |\n            2    2(2)5                                 6(7)15\n                   |                                     ^\n            3    3(3)4                            7(8)10   11(10)14\n                                                    |          |\n            4                                     8(9)9    12(11)13\n\n            level           Nested sets tree2\n            1                     1(12)28\n                     ________________|_______________________\n                    |                |                       |\n            2    2(13)5            6(15)17                18(18)27\n                   |                 ^                        ^\n            3    3(14)4    7(4)12 13(16)14  15(17)16  19(19)22  23(21)26\n                             ^                            |         |\n            4          8(5)9  10(6)11                 20(20)21  24(22)25\n\nMove after\n\n.. code:: python\n\n    node = session.query(Tree).filter(Tree.id == 8).one()\n    node.move_after(\"5\")\n\n::\n\n           level           Nested sets example\n                1                    1(1)22\n                        _______________|___________________\n                       |               |                   |\n                2    2(2)5           6(4)11             12(7)21\n                       |               ^                   ^\n                3    3(3)4       7(5)8   9(6)10    13(8)16   17(10)20\n                                                      |          |\n                4                                  14(9)15   18(11)19\n\n            level               Move 8 after 5\n                1                     1(1)22\n                         _______________|__________________\n                        |               |                  |\n                2     2(2)5           6(4)15            16(7)21\n                        |               ^                  |\n                3     3(3)4    7(5)8  9(8)12  13(6)14   17(10)20\n                                        |                  |\n                4                    10(9)11            18(11)19\n\nMove to top level\n\n.. code:: python\n\n    node = session.query(Tree).filter(Tree.id == 15).one()\n    node.move_after(\"1\")\n\n::\n\n            level           tree_id = 1\n            1                    1(1)22\n                    _______________|___________________\n                   |               |                   |\n            2    2(2)5           6(4)11             12(7)21\n                   |               ^                   ^\n            3    3(3)4       7(5)8   9(6)10    13(8)16   17(10)20\n                                                  |          |\n            4                                  14(9)15   18(11)19\n\n            level           tree_id = 2\n            1                     1(15)6\n                                     ^\n            2                 2(16)3   4(17)5\n\n            level           tree_id = 3\n            1                    1(12)16\n                     _______________|\n                    |               |\n            2    2(13)5          6(18)15\n                    |               ^\n            3    3(14)4     7(19)10   11(21)14\n                               |          |\n            4               8(20)9    12(22)13\n\nSupport and Development\n=======================\n\nTo report bugs, use the `issue tracker\n\u003chttps://github.com/uralbash/sqlalchemy_mptt/issues\u003e`_.\n\nWe welcome any contribution: suggestions, ideas, commits with new\nfutures, bug fixes, refactoring, docs, tests, translations, etc...\n\nIf you have any questions:\n\n* Use the `Discussion board \u003chttps://github.com/uralbash/sqlalchemy_mptt/discussions\u003e`_\n* Contact the maintainer via email: fayaz.yusuf.khan@gmail.com\n* Contact the author via email: sacrud@uralbash.ru or #sacrud IRC channel |IRC Freenode|\n\nRefer the detailed contribution guide in the `docs \u003chttps://sqlalchemy-mptt.readthedocs.io/CONTRIBUTING.html\u003e`_\nfor more information on setting up the development environment, running tests, and contributing to the project.\n\nLicense\n=======\n\nThe project is licensed under the MIT license.\n\n.. |PyPI Version| image:: https://img.shields.io/pypi/v/sqlalchemy_mptt\n   :alt: PyPI - Version\n.. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/sqlalchemy_mptt\n   :alt: PyPI - Downloads\n.. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/sqlalchemy_mptt\n   :alt: PyPI - Python Version\n.. |Build Status| image:: https://github.com/uralbash/sqlalchemy_mptt/actions/workflows/run-tests.yml/badge.svg?branch=master\n   :target: https://github.com/uralbash/sqlalchemy_mptt/actions/workflows/run-tests.yml\n.. |Coverage Status| image:: https://coveralls.io/repos/uralbash/sqlalchemy_mptt/badge.png\n   :target: https://coveralls.io/r/uralbash/sqlalchemy_mptt\n.. |IRC Freenode| image:: https://img.shields.io/badge/irc-freenode-blue.svg\n   :target: https://webchat.freenode.net/?channels=sacrud\n","funding_links":[],"categories":["Python","Admin interface"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furalbash%2Fsqlalchemy_mptt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furalbash%2Fsqlalchemy_mptt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furalbash%2Fsqlalchemy_mptt/lists"}