rectpack
2D Rectangle packing library
What it is and what it does
Rectpack is a 2D bin packing library that takes a set of rectangles and arranges them into the smallest number of rectangular bins using heuristic algorithms. It implements three major packing strategies—Skyline, MaxRects, and Guillotine—each with multiple variants, allowing you to trade off between packing quality and speed. The library supports both offline mode (pack all rectangles at once after they're added) and online mode (pack rectangles as they arrive), with configurable options for bin selection, rectangle sorting, and rotation.
You define rectangles and bins by their dimensions, add them to a packer object, call pack(), and then retrieve the results as a list of (bin_index, x, y, width, height, id) tuples showing where each rectangle ended up. The package has no external runtime dependencies and handles the core algorithmic work internally. However, it requires exact integer or Decimal dimensions to avoid floating-point rounding errors, and it is marked abandoned with no maintenance since late 2021.
Use it for:
- Texture atlas generation for game engines or graphics applications where sprites must be packed into minimal texture sheets.
- Print layout optimization to arrange images and text blocks on pages or posters with minimal waste.
- Warehouse or container loading where physical items must fit into the fewest trucks or storage bins.
- Cutting stock problems in manufacturing where material sheets are cut into smaller pieces with minimal scrap.
- UI layout algorithms where widgets or panels must be arranged into fixed-size containers on a screen.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Rectpack solves the 2D bin packing problem by arranging rectangles into the smallest number of bins using configurable heuristic algorithms (Skyline, MaxRects, Guillotine) with support for online and offline modes.
Yes, if you need a lightweight 2D packing solver and can tolerate abandoned software. The library is stable for its core use case, has no dependencies, and works well for offline packing problems. However, do not use it if you require active maintenance, compatibility with recent Python versions, or ongoing algorithm improvements. Test thoroughly on your target Python version before production deployment.
Install
rectpack on PyPI
pip
pip install rectpackuv
uv add rectpackpoetry
poetry add rectpackInstalling rectpack
Before you install
Installation requires building from source (high friction). The package is marked abandoned with no commits since 2021-11-24. No runtime dependencies, but the lack of recent maintenance means bug fixes and compatibility updates are unlikely.
License in practice
Licensed under Apache-2.0 (permissive), allowing commercial and private use with minimal restrictions. You may use, modify, and distribute the code freely as long as you include the license notice.
Quickstart
pip install rectpack
from rectpack import newPacker
packer = newPacker()
for w, h in [(100, 30), (40, 60)]:
packer.add_rect(w, h)
for w, h in [(300, 450), (200, 150)]:
packer.add_bin(w, h)
packer.pack()
for b, x, y, w, h, rid in packer.rect_list():
print(f"Bin {b}: rect at ({x}, {y})")
All rectangle and bin dimensions must be integers or Decimals; floating-point values will cause rounding collisions. Use the provided float2dec helper to convert floats safely.
Verify before relying
- Whether the package works reliably on modern Python versions given its abandoned status and alpha classification.
- Performance characteristics and scalability limits for large packing problems.
- Whether any of the algorithm variants (MaxRects, Skyline, Guillotine) are documented as better for specific use cases beyond the brief recommendation.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,724 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 109,668/month — #12,504 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: rectpack-0.2.2.tar.gz
Keywords: knapsack, rectangle, packing 2D, bin, binpacking
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
py3dbpSolves the 3D bin packing problem by fitting…
permissive · top 5,000 on PyPI
rectangle-packerPacks a set of rectangles with fixed…
permissive · top 15,000 on PyPI
squarifyComputes treemap layout rectangles from a list…
permissive · top 15,000 on PyPI
binpackingDistributes weighted items into bins using…
permissive · top 15,000 on PyPI
PyRectPyRect provides a Rect class for representing…
permissive · top 5,000 on PyPI
prtpyImplements multiway number partitioning and bin…
permissive · top 15,000 on PyPI
munkresImplements the Munkres algorithm (Hungarian…
permissive · top 15,000 on PyPI
PyWinBoxPyWinBox manages window positions, sizes, and…
permissive · top 15,000 on PyPI
optbinningOptBinning discretizes numeric variables into…
permissive · top 15,000 on PyPI