{"id":28308,"library":"stretchable","title":"Stretchable","description":"A Python layout library that uses Taffy, a Rust-powered implementation of CSS Grid and Flexbox, to compute layouts declaratively. Current version is 1.1.8, supporting Python >=3.8. Release cadence is irregular, approximately bi-monthly.","status":"active","version":"1.1.8","language":"python","source_language":"en","source_url":"https://github.com/mortencombat/stretchable","tags":["layout","css-grid","flexbox","taffy","rust","gui"],"install":[{"cmd":"pip install stretchable","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Auto is a sentinel value for automatic sizing.","wrong":"","symbol":"Auto","correct":"from stretchable import Auto"},{"note":"Main class for creating layout nodes.","wrong":"","symbol":"Node","correct":"from stretchable import Node"},{"note":"Used to compute and retrieve layouts.","wrong":"","symbol":"LayoutTree","correct":"from stretchable import LayoutTree"},{"note":"Defines styling properties for nodes.","wrong":"","symbol":"Style","correct":"from stretchable import Style"},{"note":"Result object containing computed layout values (e.g., left, top, width, height).","wrong":"","symbol":"Layout","correct":"from stretchable import Layout"}],"quickstart":{"code":"from stretchable import Node, LayoutTree, Style\n\n# Create a root node with flexbox layout\nroot = Node(style=Style(size={\"width\": 100, \"height\": 100}, display=\"flex\", flex_direction=\"column\", gap=10))\nchild1 = Node(style=Style(size={\"width\": 50, \"height\": 30}))\nchild2 = Node(style=Style(size={\"width\": 50, \"height\": 30}))\n\n# Build and compute layout\ntree = LayoutTree(root)\nroot.add_child(child1)\nroot.add_child(child2)\ntree.compute_layout()\n\n# Print layout of child1\nlayout = tree.get_layout(child1)\nprint(f\"Child1: left={layout.left}, top={layout.top}, width={layout.width}, height={layout.height}\")","lang":"python","description":"Quickstart: create nodes, add children, compute layout, and access results."},"warnings":[{"fix":"Call root.add_child(child) before tree.compute_layout().","message":"Nodes must be added as children before calling tree.compute_layout(), otherwise they are not part of the layout calculation.","severity":"gotcha","affected_versions":"all"},{"fix":"Refer to migration notes in GitHub releases. For custom measure functions, ensure they match the new signature (width, height, available_width, available_height).","message":"Upgrade to v1.1.0 introduced breaking changes due to Taffy 0.5.1 upgrade. CSS Block layout and overflow support were added; some APIs changed (e.g., measure function signatures).","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Use dictionary format: size={'width': 100, 'height': 50}.","message":"The size property in Style expects a dictionary, not a tuple. Common mistake: using size=(100, 50) instead of size={\"width\": 100, \"height\": 50}.","severity":"gotcha","affected_versions":"all"},{"fix":"Use node.style_setter() or modify individual properties of node.style (e.g., node.style.flex_direction = 'row').","message":"Direct assignment to Node.style (e.g., node.style = new_style) is deprecated after v1.1.1. Use setter method or property assignment carefully.","severity":"deprecated","affected_versions":">=1.1.1"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use Auto directly: size={'width': Auto, 'height': 100}.","cause":"Mistaking Auto for a function; Auto is a constant sentinel, not a callable.","error":"TypeError: 'int' object is not callable"},{"fix":"Ensure node is added as child via root.add_child(node) and call tree.compute_layout() before get_layout().","cause":"Calling tree.get_layout() for a node that hasn't been added to the tree or layout not computed.","error":"AttributeError: 'NoneType' object has no attribute 'left'"},{"fix":"Run 'pip install stretchable'. If using virtual environments, ensure it is activated.","cause":"stretchable not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'stretchable'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}