{"id":24115,"library":"newick","title":"newick","description":"A Python module to read and write the Newick format, commonly used for phylogenetic trees. Current version: 1.11.0. Release cadence is irregular; maintained on GitHub.","status":"active","version":"1.11.0","language":"python","source_language":"en","source_url":"https://github.com/glarue/newick","tags":["phylogenetics","newick","tree","parsing"],"install":[{"cmd":"pip install newick","lang":"bash","label":"install with pip"}],"dependencies":[],"imports":[{"note":"Standard import for parsing Newick strings.","symbol":"loads","correct":"from newick import loads"},{"note":"Standard import for writing Newick strings.","symbol":"dumps","correct":"from newick import dumps"},{"note":"Load Newick from a file.","symbol":"load","correct":"from newick import load"},{"note":"Write Newick to a file.","symbol":"dump","correct":"from newick import dump"}],"quickstart":{"code":"from newick import loads, dumps\n\n# Load a Newick string\ntree = loads('(A:0.1,B:0.2,(C:0.3,D:0.4):0.5);')\n# tree is a list of Node objects (rooted at index 0)\nnode = tree[0]\nprint(node.name)       # None (internal node)\nprint(node.descendants) # list of Nodes\nprint(node.length)     # None (for root)\n\n# Modify the tree and dump back to string\nnode.name = 'root'\nnewick_str = dumps(node)\nprint(newick_str)","lang":"python","description":"Parses a Newick string into a tree of Node objects and serializes back."},"warnings":[{"fix":"tree = loads(newick_str)[0]","message":"loads() returns a list of Node objects, not a single Node. For a tree with one root, access index 0.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure node names are properly escaped or quoted in the Newick string.","message":"Node names can include special characters like ':' or ',' but must be quoted. The library may fail to parse if names contain unescaped special characters.","severity":"gotcha","affected_versions":"all"},{"fix":"Use load() for reading files and dump() for writing.","message":"The 'read' and 'write' functions (from newick import read, write) are deprecated as of v1.9.0. Use load/dump instead.","severity":"deprecated","affected_versions":">=1.9.0"},{"fix":"Use 'node.parent' instead of 'node.ancestor'.","message":"In v1.9.0, the internal Node class changed: removed 'ancestor' attribute and added 'parent'. Code relying on 'node.ancestor' will break.","severity":"breaking","affected_versions":">=1.9.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade to latest: pip install --upgrade newick. Check import: from newick import loads","cause":"Installed old version (<1.0) that lacked loads/dumps; or named conflict with other module.","error":"AttributeError: module 'newick' has no attribute 'loads'"},{"fix":"Ensure the Newick string is valid and ends with ';'. Check: tree = loads(newick_str); assert tree","cause":"The Newick string is empty or malformed (e.g., missing semicolon). loads() returns empty list.","error":"IndexError: list index out of range when accessing tree[0]"},{"fix":"Use dumps(node) to serialize, not load(). load() is for reading from file.","cause":"Passed a Node object to load() instead of a file path or string.","error":"TypeError: expects a string or file-like object"},{"fix":"Quote the name using single quotes in the Newick string, e.g., \"'My:Node'\".","cause":"Node name includes unescaped newick special characters like '(', ')', ':', ',', ';'.","error":"ValueError: Node name contains illegal characters"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}