{"id":19989770,"url":"https://github.com/inspiaaa/treeprinter","last_synced_at":"2026-06-05T01:31:43.260Z","repository":{"id":108960393,"uuid":"229419279","full_name":"Inspiaaa/TreePrinter","owner":"Inspiaaa","description":"Used for printing nested tree structures","archived":false,"fork":false,"pushed_at":"2019-12-21T16:58:01.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T21:52:24.449Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Inspiaaa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-12-21T11:41:22.000Z","updated_at":"2019-12-21T16:58:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"8ffc6c19-c1e4-445f-b207-d4ef032516c8","html_url":"https://github.com/Inspiaaa/TreePrinter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Inspiaaa/TreePrinter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspiaaa%2FTreePrinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspiaaa%2FTreePrinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspiaaa%2FTreePrinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspiaaa%2FTreePrinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Inspiaaa","download_url":"https://codeload.github.com/Inspiaaa/TreePrinter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspiaaa%2FTreePrinter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33927313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-04T02:00:06.755Z","response_time":64,"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":[],"created_at":"2024-11-13T04:50:05.080Z","updated_at":"2026-06-05T01:31:43.232Z","avatar_url":"https://github.com/Inspiaaa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Treeprinter\n![Python 3.7](https://img.shields.io/badge/Python-3.x-blue.svg?style=for-the-badge\u0026logo=python)\nA simple python script to recursively print a nested tree structure. It's simple to use and can support a tree structure containing user defined types.\nVery useful for visualising nested data such as:\n\n - File structure\n - Abstract syntax tree\n\n---\n## Getting started\n\nCopy the script into your local workspace and import it\n```python\nimport tree_printer as tp\n```\n\n\u003e If you want you can import it as `tp` because `tree_printer` can be quite annoying to type in every time you need it\n\nTo use it you have to instantiate a `TreePrinter` instance and declare a dispatch table which defines how the printer should handle each type. The dispatch table is a dictionary. To then print you must simply call the `print` method of your printer instance.\n\nAn example:\n```python\nimport tree_printer as tp\n\n\ndata = {  \n    \"Eras\": {  \n        \"Baroque\": [\"Bach\", \"Händel\"],  \n        \"Classical\": [\"Mozart\", \"Schubert\", \"Beethoven\"],  \n        \"Romantic\": [\"Chopin\", \"Dvorak\"],  \n        \"Modern\": [\"Ravel\"]  \n    }  \n}\n\ndispatch_table = {\n\tdict: lambda d: [tp.Entry(key, [value]) for key, value in d.items()],\n\tlist: lambda l: [tp.Entry(value) for value in l]\n}\n\nprinter = tp.TreePrinter(dispatch_table)  \nprinter.print(\"History of Music\", data)\n```\nConsole:\n```\nHistory of Music\n└──Eras\n   ├──Baroque\n   │  ├──Bach\n   │  └──Händel\n   ├──Classical\n   │  ├──Mozart\n   │  ├──Schubert\n   │  └──Beethoven\n   ├──Romantic\n   │  ├──Chopin\n   │  └──Dvorak\n   └──Modern\n      └──Ravel\n```\n\nThe dispatch table's keys are the type you want to handle. For example, to handle a `list` the key must be `list`. The value of it is a lambda that takes the instance of that list as an argument and returns a `tp.Entry` or a list of `tp.Entry`.\n```python\n{list: lambda instance: tp.Entry(\"Header\", [])}\n```\n\nThe first argument of the `Entry` constructor is the header and the second argument is a `list` of all its children.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspiaaa%2Ftreeprinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finspiaaa%2Ftreeprinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspiaaa%2Ftreeprinter/lists"}