anytree
anytree copied to clipboard
Share your anytree projects
Please like this ticket, if you are using anytree.
Feel free to share infos about your project.
Thanks for anytree, it's an awesome library that allowed me to create this little project: https://github.com/deadc0de6/catcli - a CLI indexer for your offline data
I am using anytree's NodeMixin class to render dependency trees in johnnydep. Here is an example of johnnydep rendering the dep tree for the catcli project mentioned above:
$ johnnydep catcli
name summary
------------------ ---------------------------------------------------------------
catcli The command line catalog tool for your offline data
├── anytree Powerful and Lightweight Python Tree Data Structure..
│ └── six>=1.9.0 Python 2 and 3 compatibility utilities
├── docopt Pythonic argument parser, that will make you smile
└── psutil Cross-platform lib for process and system monitoring in Python.
And here is johnnydep rendering its own dependency tree:
$ johnnydep johnnydep
name summary
------------------------ --------------------------------------------------------------------------
johnnydep Display dependency tree of Python distribution
├── anytree Powerful and Lightweight Python Tree Data Structure..
│ └── six>=1.9.0 Python 2 and 3 compatibility utilities
├── cachetools Extensible memoizing collections and decorators
├── colorama Cross-platform colored terminal text.
├── oyaml Ordered YAML: drop-in replacement for PyYAML which preserves dict ordering
│ └── pyyaml YAML parser and emitter for Python
├── packaging>=17 Core utilities for Python packages
│ ├── pyparsing>=2.0.2 Python parsing module
│ └── six Python 2 and 3 compatibility utilities
├── pip The PyPA recommended tool for installing Python packages.
├── pkginfo>=1.4.2 Query metadatdata from sdists / bdists / installed packages.
├── pytoml A parser for TOML-0.4.0
├── setuptools>=38.3 Easily download, build, install, upgrade, and uninstall Python packages
├── structlog Structured Logging for Python
│ └── six Python 2 and 3 compatibility utilities
├── tabulate Pretty-print tabular data
├── wheel>=0.31.0 A built-package format for Python.
└── wimpy Anti-copy-pasta
Anytree is used to model and navigate the modular data structure of lbuild: a generic, modular code generator.
$ lbuild discover
Parser(lbuild)
╰── Repository(modm @ ../../..) modm: a barebone embedded library generator
├── EnumerationOption(target) = stm32f469nih in [at90can128, at90can32, at90can64, ...
├── Module(modm:build) Build System Generators
│ ├── StringOption(build.path) = ../../../build/stm32f469_discovery/game_of_life ...
│ ├── StringOption(openocd.cfg) = "" in [String]
│ ├── StringOption(project.name) = game_of_life in [String]
│ ├── Module(modm:build:cmake) CMake Build Script Generator
│ │ ╰── BooleanOption(include_makefile) = True in [True, False]
│ ╰── Module(modm:build:scons) SCons Build Script Generator
│ ├── StringOption(cache_dir) = /cache in [String]
│ ├── StringOption(image.source) = "" in [String]
│ ├── BooleanOption(include_sconstruct) = True in [True, False]
│ ├── BooleanOption(info.build) = False in [True, False]
│ ╰── EnumerationOption(info.git) = Disabled in [Disabled, Info, Info+Status]
├── Module(modm:platform) Platform HAL
│ ├── Module(modm:platform:1-wire.bitbang) Software 1-Wire
│ ├── Module(modm:platform:adc) Analog-to-Digital Converter (ADC)
│ │ ├── Module(modm:platform:adc:1) Instance 1
│ │ ├── Module(modm:platform:adc:2) Instance 2
│ │ ╰── Module(modm:platform:adc:3) Instance 3
│ ├── Module(modm:platform:can) Controller Area Network (CAN)
│ │ ├── Module(modm:platform:can:1) Instance 1
│ │ │ ├── NumericOption(buffer.rx) = 32 in [1 .. 32 .. 65534]
│ │ │ ╰── NumericOption(buffer.tx) = 32 in [1 .. 32 .. 65534]
│ │ ╰── Module(modm:platform:can:2) Instance 2
│ │ ├── NumericOption(buffer.rx) = 32 in [1 .. 32 .. 65534]
│ │ ╰── NumericOption(buffer.tx) = 32 in [1 .. 32 .. 65534]
│ ├── Module(modm:platform:can.common) CAN Common
│ ├── Module(modm:platform:clock) Reset and Clock Control (RCC)
│ ├── Module(modm:platform:clock.cortex) ARM Cortex-M SysTick
│ ├── Module(modm:platform:core) STM32 core module
│ ├── Module(modm:platform:cortex-m) ARM Cortex-M Core
│ │ ├── EnumerationOption(allocator) = tlsf in [block, newlib, tlsf]
│ │ ├── StringOption(linkerscript.memory) = SDRAM (rwx) : ORIGIN = 0xC0000000, ...
│ │ ├── StringOption(linkerscript.sections) = .sdramdata : { ...
│ │ ├── StringOption(linkerscript.table_extern.copy) = LONG (__sdramdata_load) ...
│ │ ├── StringOption(linkerscript.table_extern.heap) = LONG (0x801f) L ...
│ │ ├── StringOption(linkerscript.table_extern.zero) = "" in [String]
│ │ ├── NumericOption(main_stack_size) = 3040 in [256 .. 3040 .. 65536]
│ │ ├── BooleanOption(stack_execution_guard) = False in [True, False]
│ │ ├── EnumerationOption(vector_table_location) = rom in [ram, rom]
│ │ ╰── PropertyQuery(substitutions)
...
It's also really nice to customize (we're using : as separator, and it just works™), extended path resolver filling in blanks using context (ie. ::scons is unique, expands to modm:build:scons), extended node rendering (we make some text bold and underline to make it easier to see options).
This is a great project, simple to use, well documented, just works as advertised. Thanks a lot!
A classmate and I did an AI course project that generates Pokemon-playing scripts. We used anytree to create abstract syntax tree.
So an AST like this:
Rule.START
└── Rule.IF_BLOCK
├── Rule.BOOL_EXP
│ └── Rule.AND_EXP
│ ├── Rule.BOOL
│ │ └── Rule.LIB_CALL
│ │ ├── dsl.player_base_spec_defense
│ │ ├── Rule.NUM_COMPARATOR
│ │ │ └── <=
│ │ └── Rule.INT_NUM
│ │ └── 194
│ └── Rule.BOOL
│ └── Rule.LIB_CALL
│ ├── dsl.check_move_sds_if_hits_opp
│ └── move
└── Rule.IF_BODY
└── Rule.CHANGE_SCORE
└── Rule.SCORE_NUM
└── 5
Would be rendered as this:
class Script_9f8ccd13db044ef19aef7d204b40a325(Script):
def choose_move(self, battle: Battle):
available_moves = battle.available_moves
if not available_moves:
return self.choose_random_move(battle)
dsl = DSL(battle)
move_scores = []
for move in battle.available_moves:
score = 0
if (((dsl.player_base_spec_defense() <= 194) and dsl.check_move_sds_if_hits_opp(move))):
score += 5
move_scores.append(score)
best_move = available_moves[move_scores.index(max(move_scores))]
return best_move
Please like this ticket, if you are using anytree.
Feel free to share infos about your project.
Hello, I felt the need to get into Python syntax and way of thinking so I decided to build a lightweight ToDo app, and your solution for building trees felt like a perfect helping hand. Feel free to check it out here
Hi! I used a lot anytree at my work for representing and manipulating hierarchical data in different contexts. It is a great library, with a simple yet powerful interface and very well documented.
I also wrote a short blog post about it, check it out here.
Thanks for developing this library!
I packaged anytree for Alpine Linux (here), and use it in a Linux mobile-friendly password-store app: caerbannog
Thanks for the great library!
We are using it in a machine learning project which deals with hierarchical data. It is private unfortunately and cannot give many details, but it such a huge help versus our old internal library.
I used anytree to render a tree and here's the restriction I came up with. New to python, hence may not be seeing the light. In my case, a parent P1(attributes ap1) connects to a child C1(attributes ac1). I have another connection of parent P1(attributes ap2) to child C1(attributes ac2) and so on and so forth. So basically I need any array of attributes at every level with attributes depicted as jsons(dict).The attributes here lets me denote the different link pairs between the same parent and child. How can I achieve this ?
P1 [{its connection attributes to its parent like below}] |-----C1[{parentAttrib:ap1,childAttrib:ac1},{parentAttrib:ap2,childAttrib:ac2}]
Thanks in advance!
I used NodeMixin class and it was easy. Thinking a little more, I think I could do it using plain Node as well. I could do a hasattrib and find if the attributes exists, if does not then add a list to the attributes and add the data element. So everytime need to check if it exists or not before creating or appending an object(dict in my case). Though not implemented this.
Thanks again for the wonderful library.
i used a combination of anytree and Rich to build the pdfalyzer, a tool to help visualize the logical structure of a PDF with an eye to finding malicious content. anytree handles the data model, rich handles the presentation. there's some images on the pdfalyzer's repo page, or here's an even bigger example showing the glory of the tree.
great library. since Rich added their own tree visualization tool not that long ago, putting them together is a super low cost way to get really great visualizations. SymlinkNode was particularly useful for this use case because PDFs contain lots of links between nodes beyond parent/child.
(and here's a twitter thread if you're curious about why i did that and what i did with it once i built it)
Thanks for the library. I used it to visualize ASTs built by a compiler that I'm writing.
Can I create two different nodes with the same display name?
If I create two Nodes with the same name using the Node(..) constructor, both the nodes get merged into one.
@RamneekSingh24 the NodeMixin class allows you to build a tree out of arbitrary python objects, at which point the sky's the limit as far as names etc.