{"id":10194,"library":"rectangle-packer","title":"Rectangle Packer","description":"rectangle-packer is a Python library for efficiently packing a set of 2D rectangles into a minimal bounding box. It utilizes an optimized best-fit heuristic algorithm to achieve high packing density. The current stable version is 2.1.0, and it maintains a moderate release cadence, with updates addressing performance and edge cases, primarily focusing on its core `pack` functionality.","status":"active","version":"2.1.0","language":"python","source_language":"en","source_url":"https://github.com/Penlect/rectangle-packer","tags":["packing","rectangle","layout","bin-packing","optimization"],"install":[{"cmd":"pip install rectangle-packer","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"pack","correct":"from rpack import pack"},{"note":"The 'group' function was removed in version 2.0.6. Use 'rpack.pack' directly.","wrong":"from rpack import group","symbol":"group","correct":"from rpack import pack # 'group' was removed"},{"note":"The internal '_rpack' extension module was removed in version 2.0.6. Use 'rpack.pack' directly.","wrong":"import rpack._rpack","symbol":"_rpack","correct":"from rpack import pack # '_rpack' was removed"}],"quickstart":{"code":"import rpack\n\n# Rectangles are defined as (width, height) tuples\nrects = [\n    (10, 20),\n    (5, 15),\n    (12, 12),\n    (30, 10),\n    (8, 25)\n]\n\n# Pack the rectangles, returns a list of (x, y) positions\n# (0,0) is top-left, increasing x to the right, increasing y downwards\npositions = rpack.pack(rects)\n\n# The positions correspond to the input rectangles order\nfor i, (x, y) in enumerate(positions):\n    print(f\"Rectangle {i+1} (w={rects[i][0]}, h={rects[i][1]}): Position ({x}, {y})\")\n\n# You can find the enclosing dimensions of the packed layout\nwidth, height = rpack.util.enclosing_size(rects, positions)\nprint(f\"Total enclosing size: Width={width}, Height={height}\")","lang":"python","description":"This quickstart demonstrates how to define a list of rectangles as (width, height) tuples and use `rpack.pack()` to find their optimal positions within a minimal bounding box. It then prints the calculated (x, y) positions for each rectangle and the overall dimensions of the packed area."},"warnings":[{"fix":"Migrate any usage of `rpack.group` or direct calls to `rpack._rpack.pack` to use `rpack.pack` directly. The `pack` function is now the sole public API for packing.","message":"The `rpack.group` function and the internal `rpack._rpack` extension module were removed in version 2.0.6. These were part of the older API and have been consolidated.","severity":"breaking","affected_versions":">=2.0.6"},{"fix":"Upgrade to version 2.1.0 or newer. This version introduced bigint preprocessing, including `gcd` normalization and power-of-two scaling, to robustly handle very large Python integers.","message":"Prior to version 2.1.0, packing rectangles with extremely large width/height values (exceeding standard C `long` limits) could lead to `OverflowError` or incorrect results due to integer overflow in the underlying C extension.","severity":"gotcha","affected_versions":"<2.1.0"},{"fix":"Upgrade to version 2.1.0 or newer. This version significantly improved `rpack.pack()` search behavior for such inputs by adding staged coarse candidate stepping with bounded local refinement.","message":"Performance and packing density for 'thin' or 'pathological' rectangle inputs (e.g., 1x1000) were less optimal in versions prior to 2.1.0.","severity":"gotcha","affected_versions":"<2.1.0"}],"env_vars":null,"search_vec":"'2.1.0':42 '2d':16 'achiev':33 'address':52 'algorithm':31 'best':28 'best-fit':27 'bin':68 'bin-pack':67 'bound':21 'box':22 'cadenc':49 'case':56 'core':61 'current':38 'densiti':36 'edg':55 'effici':11 'fit':29 'focus':58 'function':63 'heurist':30 'high':34 'layout':66 'librari':9 'maintain':45 'minim':20 'moder':47 'optim':26,70 'pack':12,35,62,64,69 'packer':2,5 'perform':53 'primarili':57 'python':8 'rectangl':1,4,17,65 'rectangle-pack':3 'releas':48 'set':14 'stabl':39 'updat':51 'util':24 'version':40","created_at":"2026-04-17T01:22:52.424119+00:00","updated_at":"2026-04-17T01:22:52.424119+00:00","problems":[{"fix":"Upgrade to `rectangle-packer` version 2.0.6 or newer and use `rpack.pack` directly. If you need to pack independent sets of rectangles, call `rpack.pack` for each set.","cause":"The `rpack.group` function was removed in version 2.0.6. It was part of an older API for packing multiple groups of rectangles.","error":"AttributeError: module 'rpack' has no attribute 'group'"},{"fix":"Upgrade to `rectangle-packer` version 2.0.6 or newer. The core packing functionality is now directly exposed via `rpack.pack`. Avoid importing internal modules directly.","cause":"The internal `_rpack` extension module was removed in version 2.0.6 as part of API simplification and consolidation.","error":"ImportError: cannot import name '_rpack' from 'rpack'"},{"fix":"Upgrade to `rectangle-packer` version 2.1.0 or newer. This version includes robust bigint preprocessing to handle large Python integers correctly without overflow.","cause":"This error occurs in versions prior to 2.1.0 when `rpack.pack` is given rectangles with extremely large width or height values that exceed the capacity of the underlying C `long` integer type.","error":"OverflowError: Python int too large to convert to C long"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.1.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Penlect/rectangle-packer","docs":null,"changelog":null,"pypi":"https://pypi.org/project/rectangle-packer/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}