{"id":24732,"library":"treeswift","title":"TreeSwift","description":"TreeSwift is a fast tree manipulation library for Python 2 and 3, providing a simple interface for reading, writing, and analyzing phylogenetic trees. The current version is 1.1.45, with regular updates and bug fixes.","status":"active","version":"1.1.45","language":"python","source_language":"en","source_url":"https://github.com/niemasd/TreeSwift","tags":["phylogenetics","tree","bioinformatics","newick","nexus"],"install":[{"cmd":"pip install treeswift","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"read_tree is a function; Tree is the class.","wrong":"from treeswift import read_tree","symbol":"Tree","correct":"from treeswift import Tree"},{"note":"Node is exported from treeswift directly.","wrong":"from treeswift.tree import Node","symbol":"Node","correct":"from treeswift import Node"}],"quickstart":{"code":"from treeswift import Tree\n\ntree = Tree()\ntree.read('((A:0.1,B:0.2):0.3,C:0.4);')\nprint(tree)  # Newick string\n\ndist = tree.distance_between('A', 'C')\nprint(dist)  # 0.8","lang":"python","description":"Initialize a tree, read a Newick string, print the tree, and compute the distance between two leaves."},"warnings":[{"fix":"Use `extract_tree_with(set(['ABC']))` or `extract_tree_with(['ABC'])` to keep the label intact.","message":"`extract_tree_with` and `extract_tree_without` convert string input to a set of individual characters. If you pass a single string like 'ABC', it will be treated as {'A','B','C'} rather than preserving the string as a single label. Pass a set or list instead.","severity":"gotcha","affected_versions":"<=1.1.41"},{"fix":"Pass an open file handle or a path; gzip is detected internally.","message":"`Tree.read` can read gzip files directly, but file extension handling may be simplified in future versions.","severity":"deprecated","affected_versions":"all"},{"fix":"Upgrade to >=1.1.39: `pip install --upgrade treeswift`.","message":"`distance_between` may return incorrect values when one node is an ancestor of the other in versions prior to 1.1.39. Ensure you have the latest version.","severity":"gotcha","affected_versions":"<1.1.39"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install treeswift` in the correct Python environment.","cause":"Library not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'treeswift'"},{"fix":"Wrap the string in a list: `tree.extract_tree_with(['label'])` instead of `tree.extract_tree_with('label')`.","cause":"Passing a string directly to `extract_tree_with` where an iterable of labels is expected.","error":"TypeError: extract_tree_with() argument after * must be an iterable, not str"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}