{"id":28135,"library":"rectpack","title":"rectpack - 2D Rectangle Packing","description":"A Python library for packing 2D rectangles into a bin using various algorithms (MaxRects, Guillotine, etc.). Supports rotation, sorting, and multiple packing modes. Current version 0.2.2, maintained infrequently.","status":"active","version":"0.2.2","language":"python","source_language":"en","source_url":"https://github.com/secnot/rectpack/","tags":["rectangle packing","bin packing","2D packing","MaxRects","Guillotine"],"install":[{"cmd":"pip install rectpack","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Wrong import causes ModuleNotFoundError.","wrong":"import Packer","symbol":"Packer","correct":"from rectpack import Packer"},{"note":"Direct submodule import fails; all packers are exposed at package level.","wrong":"from rectpack.maxrects import MaxRectsBssf","symbol":"MaxRectsBssf","correct":"from rectpack import MaxRectsBssf"},{"note":"Same as above; use package-level imports.","wrong":"from rectpack.guillotine import GuillotineBssfSas","symbol":"GuillotineBssfSas","correct":"from rectpack import GuillotineBssfSas"}],"quickstart":{"code":"from rectpack import Packer, MaxRectsBssf\nfrom rectpack import SORT_AREA\n\npacker = Packer()\n# Use a packing algorithm\npacker.add_bin(100, 100)\npacker.add_rect(50, 30, rid='rect1')\npacker.add_rect(20, 40, rid='rect2')\npacker.pack_algo = MaxRectsBssf()\npacker.sort_algo = SORT_AREA\npacker.pack()\nfor rect in packer.rect_list():\n    print('Rectangle:', rect)\n# Alternatively, get a summary\nprint('Bins:', packer.bins)  # list of Bin objects\nprint('Unpacked:', packer.unused_areas())","lang":"python","description":"Basic packing of two rectangles into a 100x100 bin using MaxRects BSSF algorithm."},"warnings":[{"fix":"After packing, iterate packer.rect_list() and compare with input counts to detect unplaced rectangles.","message":"The library does not check if a rectangle fits before packing. If no bin can accommodate, the rectangle is silently left unpacked. Always check packer.rect_list() against your input.","severity":"gotcha","affected_versions":"all"},{"fix":"Use: packer.pack_algo = MaxRectsBssf() (with parentheses)","message":"The attribute 'pack_algo' is being replaced by 'pack_algo' usage as a property. In older examples, they assigned the algorithm class directly; now use an instance.","severity":"deprecated","affected_versions":"<0.2.0"},{"fix":"Always provide unique rid strings, e.g., f'rect_{i}'.","message":"Rectangles added without 'rid' will be assigned a default id (e.g., 'rect_0'). If multiple rectangles have the same rid, later ones overwrite earlier ones in internal dictionary. Use unique rid per rectangle to avoid data loss.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use 'from rectpack import Packer'.","cause":"Importing 'import rectpack' then trying 'rectpack.Packer' works, but if you use 'from rectpack import *' and then 'Packer', it may not be included if __all__ is missing. But typical wrong import is 'import Packer'.","error":"AttributeError: module 'rectpack' has no attribute 'Packer'"},{"fix":"Ensure you assign packer.pack_algo = MaxRectsBssf() (note: 'pack_algo' not 'pack_algorithm').","cause":"The 'pack_algo' attribute is set after creation; may be due to spelling (pack_algo vs pack_algo) or setting it before calling pack.","error":"AttributeError: 'Packer' object has no attribute 'pack_algo'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}