{"id":7983,"library":"binpacking","title":"binpacking","description":"The `binpacking` library provides heuristic algorithms for distributing weighted items into bins. It supports scenarios with either a fixed number of bins or a fixed volume per bin, accepting data as lists, dictionaries, tuples, or CSV files. The current version is 2.0.1, and it has an active release cadence, with major updates and bug fixes released periodically.","status":"active","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/benmaier/binpacking","tags":["binpacking","optimization","algorithm","packing","knapsack","python3"],"install":[{"cmd":"pip install binpacking","lang":"bash","label":"Standard Installation"},{"cmd":"pip install binpacking[numpy]","lang":"bash","label":"With NumPy Acceleration"}],"dependencies":[{"reason":"Optional dependency for accelerated performance on large datasets. Install with `pip install binpacking[numpy]`.","package":"numpy","optional":true}],"imports":[{"note":"This is one of the primary functions for bin packing with a fixed maximum volume per bin.","symbol":"to_constant_volume","correct":"import binpacking\nbins = binpacking.to_constant_volume(items, volume)"},{"note":"This is one of the primary functions for bin packing into a fixed number of bins.","symbol":"to_multiple_bins","correct":"import binpacking\nbins = binpacking.to_multiple_bins(items, num_bins)"}],"quickstart":{"code":"import binpacking\n\n# Example 1: Pack items into bins with a constant volume limit\nitems_by_weight = {'itemA': 10, 'itemB': 20, 'itemC': 30, 'itemD': 40, 'itemE': 15}\nmax_bin_volume = 50\nbins_constant_volume = binpacking.to_constant_volume(items_by_weight, max_bin_volume)\nprint(f\"Bins (constant volume {max_bin_volume}): {bins_constant_volume}\")\n\n# Example 2: Pack items into a fixed number of bins\nnum_target_bins = 2\nbins_multiple_bins = binpacking.to_multiple_bins(items_by_weight, num_target_bins)\nprint(f\"Bins (fixed number {num_target_bins}): {bins_multiple_bins}\")\n\n# For NumPy accelerated functions, ensure it's installed via: pip install binpacking[numpy]\n# from binpacking.matrices import to_constant_volume_numpy # (advanced usage)\n","lang":"python","description":"This quickstart demonstrates the two primary bin packing functions: `to_constant_volume` for packing into bins with a maximum capacity, and `to_multiple_bins` for packing into a predefined number of bins. Items are provided as a dictionary where keys are item identifiers and values are their weights or sizes."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or later. If unable to upgrade, you must use `binpacking` version < 2.0.0 (e.g., `pip install binpacking==1.5.2`).","message":"Version 2.0.0 and above require Python 3.10 or newer. Older Python 3 versions (e.g., 3.8, 3.9) and Python 2.x are no longer supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your build environment supports PEP 517/518 and `pyproject.toml` for packaging operations.","message":"The packaging system transitioned from `setup.py`/`setup.cfg` to `pyproject.toml` in version 2.0.0. This primarily affects maintainers or developers building from source, but it's part of the modernization effort.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always upgrade to version 2.0.1 or later (`pip install --upgrade binpacking`) to resolve this compatibility issue. Version 2.0.1 replaced PEP 695 syntax with TypeVar-based generics for broader compatibility.","message":"Version 2.0.0 had a bug related to PEP 695 generic syntax compatibility with certain Python 3.10/3.11 environments, which could lead to runtime errors.","severity":"gotcha","affected_versions":"2.0.0"},{"fix":"Install with `pip install binpacking[numpy]`.","message":"To leverage NumPy for accelerated performance, you must explicitly install `binpacking` with the `[numpy]` extra. Standard installation does not include NumPy, and any attempts to use NumPy-specific features will fail.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Ensure `pytest-runner` is not a direct or indirect dependency in your project to avoid potential security risks. Upgrade to `binpacking` v1.5.2 or newer.","message":"The `pytest-runner` dependency was removed in v1.5.2 due to security concerns.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Upgrade your Python environment to 3.10 or later. Alternatively, if unable to upgrade, install an older compatible version: `pip install binpacking==1.5.2`.","cause":"Attempting to install or run binpacking v2.0.0+ on an unsupported Python version (older than 3.10).","error":"ERROR: Package 'binpacking' requires Python '>=3.10' but the running Python is X.Y.Z"},{"fix":"Install `binpacking` with NumPy support: `pip install binpacking[numpy]`.","cause":"Attempting to use advanced features that rely on NumPy acceleration without having installed the optional `[numpy]` extra.","error":"ModuleNotFoundError: No module named 'numpy'"},{"fix":"Upgrade `binpacking` to version 2.0.1 or newer: `pip install --upgrade binpacking`. This version fixed the generic syntax implementation.","cause":"This error likely occurred in version 2.0.0 due to a compatibility issue with PEP 695 generic syntax on some Python 3.10/3.11 environments.","error":"TypeError: 'type' object is not subscriptable"}]}