Skip to main content

U-Nesting

A high-performance 2D/3D spatial optimization engine for nesting and bin packing problems.

PyPI version License: MIT

Features

  • 2D Nesting: Optimal placement of irregular polygons on sheets
  • 3D Bin Packing: Efficient box placement in containers
  • Multiple Algorithms: BLF, NFP-guided, Genetic Algorithm, BRKGA, Simulated Annealing
  • High Performance: Written in Rust with Python bindings
  • Type Hints: Full type annotation support

Installation

pip install u-nesting

Quick Start

2D Nesting

import u_nesting

# Define polygons to nest
geometries = [
    {
        "id": "part1",
        "polygon": [[0, 0], [100, 0], [100, 50], [0, 50]],
        "quantity": 5,
        "rotations": [0, 90, 180, 270]
    },
    {
        "id": "triangle",
        "polygon": [[0, 0], [80, 0], [40, 60]],
        "quantity": 3
    }
]

# Define sheet boundary
boundary = {"width": 500, "height": 300}

# Configure solver
config = {
    "strategy": "nfp",      # Options: blf, nfp, ga, brkga, sa
    "spacing": 2.0,         # Gap between parts
    "time_limit_ms": 30000  # 30 second timeout
}

# Solve
result = u_nesting.solve_2d(geometries, boundary, config)

print(f"Utilization: {result['utilization']:.1%}")
print(f"Placed: {len(result['placements'])} items")
for p in result['placements']:
    print(f"  {p['geometry_id']}[{p['instance']}]: ({p['position'][0]:.1f}, {p['position'][1]:.1f})")

3D Bin Packing

import u_nesting

# Define boxes to pack
geometries = [
    {
        "id": "small",
        "dimensions": [20, 20, 20],
        "quantity": 10
    },
    {
        "id": "large",
        "dimensions": [40, 30, 25],
        "quantity": 5,
        "mass": 2.5  # Optional weight
    }
]

# Define container
boundary = {
    "dimensions": [200, 150, 100],
    "max_mass": 50.0,    # Optional mass limit
    "gravity": True,     # Stack from bottom
    "stability": True    # Require stable placement
}

# Configure solver
config = {
    "strategy": "ep",       # Extreme Point heuristic
    "time_limit_ms": 10000
}

# Solve
result = u_nesting.solve_3d(geometries, boundary, config)

print(f"Utilization: {result['utilization']:.1%}")
print(f"Containers used: {result['boundaries_used']}")

API Reference

solve_2d(geometries, boundary, config=None) -> dict

Solve a 2D nesting problem.

Parameters:

  • geometries: List of geometry definitions
    • id (str): Unique identifier
    • polygon (list): Vertices as [[x, y], ...]
    • quantity (int): Number of copies (default: 1)
    • rotations (list): Allowed rotation angles in degrees
    • allow_flip (bool): Allow horizontal flip
    • holes (list): Interior holes as list of polygons
  • boundary: Sheet definition
    • width, height (float): Rectangle dimensions, OR
    • polygon (list): Custom boundary shape
  • config: Solver configuration (optional)
    • strategy (str): "blf", "nfp", "ga", "brkga", "sa"
    • spacing (float): Gap between geometries
    • margin (float): Gap from boundary
    • time_limit_ms (int): Timeout in milliseconds
    • population_size (int): GA/BRKGA population
    • max_generations (int): GA/BRKGA generations
    • multi_sheet (bool): Distribute overflow across multiple sheets (default: False). When True, parts that do not fit on one sheet spill onto extra sheets instead of becoming unplaced; boundaries_used reports the sheet count and each placement's boundary_index selects its sheet with sheet-local coordinates.

Returns: Dictionary with:

  • success (bool): Whether solve succeeded
  • placements (list): Placement results (instance-level)
  • utilization (float): Area utilization ratio
  • boundaries_used (int): Number of sheets used (>1 only when multi_sheet=True)
  • total_requested (int): Σ of every geometry's quantity (instance-level total). Unplaced instance count = total_requested - len(placements)
  • unplaced (list): Deduplicated IDs of items that couldn't be placed (not per-instance, so len(unplaced) under-reports the failed-instance count)
  • computation_time_ms (int): Solve time

solve_3d(geometries, boundary, config=None) -> dict

Solve a 3D bin packing problem.

Parameters:

  • geometries: List of box definitions
    • id (str): Unique identifier
    • dimensions (list): [width, depth, height]
    • quantity (int): Number of copies
    • mass (float): Weight (optional)
  • boundary: Container definition
    • dimensions (list): [width, depth, height]
    • max_mass (float): Weight limit (optional)
    • gravity (bool): Enable gravity constraint
    • stability (bool): Enable stability constraint
  • config: Same as solve_2d, plus:
    • strategy: "blf", "ep", "ga", "brkga", "sa"

Returns: Same structure as solve_2d

Strategy Selection Guide

Strategy Speed Quality Best For
blf Fast Good Large instances, quick results
nfp Medium Better 2D with complex shapes
ep Fast Good 3D bin packing
ga Slow Best Small instances, max quality
brkga Slow Best Complex constraints
sa Medium Better Balanced speed/quality

Requirements

  • Python 3.8+
  • No additional dependencies

License

MIT License - see LICENSE for details.

Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

u_nesting-0.5.2-cp38-abi3-win_amd64.whl (472.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

u_nesting-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (597.5 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

u_nesting-0.5.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (545.5 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

u_nesting-0.5.2-cp38-abi3-macosx_11_0_arm64.whl (512.0 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

u_nesting-0.5.2-cp38-abi3-macosx_10_12_x86_64.whl (562.5 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file u_nesting-0.5.2-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: u_nesting-0.5.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 472.8 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for u_nesting-0.5.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7438cfa79c0401ef01d229115c5a6b302d0287fe1f430a5235cca478d51ee1ed
MD5 c994a5b4fa9d38fac6723561f898ad23
BLAKE2b-256 919449dde760a4f5bb038f1ef6096af1d6539ae3ff8f1838e66935dcfffe42b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for u_nesting-0.5.2-cp38-abi3-win_amd64.whl:

Publisher: python-publish.yml on iyulab/u-nesting

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file u_nesting-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for u_nesting-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0d681917a3714574f28ab64be4629e02afdb2bf5a424bef620db6bab009709c
MD5 220ba4420896f8f2a2f5e522f8a29c3c
BLAKE2b-256 d6aedd12b7f0da95cef1f46e0f966f314299f79482d522a76ddad2b0c7b9227d

See more details on using hashes here.

Provenance

The following attestation bundles were made for u_nesting-0.5.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on iyulab/u-nesting

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file u_nesting-0.5.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for u_nesting-0.5.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 69d49e3341c34aff854a51d8b166c89df3d131776da017133baa334be914d7e2
MD5 7d9288619da732e704783dd8335300bf
BLAKE2b-256 1d5c16b2b4b84eca76fe513bf89f54c8f8c7deaba2488aa923420231001f4d1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for u_nesting-0.5.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: python-publish.yml on iyulab/u-nesting

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file u_nesting-0.5.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for u_nesting-0.5.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7729dd230013de051351ebfb1b4368b4f0c12ab0753b1630812aa6a6fc5fa0f
MD5 7bd9eb62d23ae11f36a9f53202d9f05d
BLAKE2b-256 15381b1c1d1aad5b6d2ae2769d49412397c1b3122bc22a7328573b2c901e0133

See more details on using hashes here.

Provenance

The following attestation bundles were made for u_nesting-0.5.2-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on iyulab/u-nesting

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file u_nesting-0.5.2-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for u_nesting-0.5.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d70ad4a550f07dd8e5d7011586e011e985f33646f645bb7d2204d18d9b4cf825
MD5 9cf3915be7070e93599564e214cf7117
BLAKE2b-256 757a11ef346a51d9625ad96a4030b52002908e1c51883134e23e22bd6c1538e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for u_nesting-0.5.2-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: python-publish.yml on iyulab/u-nesting

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page