Registry / data / prtpy
library0.8.3pypypi✓ verified 87d ago

prtpy is a Python library for number partitioning. It provides various algorithms to divide a list of numbers into a specified number of subsets, typically aiming to minimize the largest sum of a subset. It is actively maintained, with the current version being 0.8.3, and releases occur as new algorithms, improvements, or bug fixes are introduced.

pip install prtpy
INSTALL
IMPORT
SIG · PRTPY
P
prtpy
datapythonv0.8.3
Install
11.2s avg
Import
398ms
Disk
525MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 12.05s
py 3.11
✓ —
✓ 11.8s
py 3.12
✕ build_error
✓ 11.4s
py 3.13
✕ build_error
✓ 11.55s
py 3.9
✓ —
✓ 9.2s
525MB installed
● package 525MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

partition
from prtpy import partition
Imports the main partitioning wrapper function.
greedy
from prtpy.partition import greedy
Imports a specific partitioning algorithm (e.g., greedy).
ilp
from prtpy.partition import ilp
Imports the ILP partitioning algorithm, which requires the `pulp` package and an installed solver.

This quickstart demonstrates how to use `prtpy` to partition a list of numbers into a specified number of bins using the greedy algorithm. The `partition` function acts as a general interface, accepting the algorithm as a parameter.

from prtpy import partition from prtpy.partition import greedy numbers = [3, 4, 5, 6, 7, 8, 9, 10] num_bins = 3 # Partition the numbers into 3 bins using the greedy algorithm result = partition(algorithm=greedy, num_bins=num_bins, items=numbers) print(f"Original numbers: {numbers}") print(f"Number of bins: {num_bins}") print(f"Partition result (greedy): {result}") # Expected output for the given input might be similar to: [[10, 8, 3], [9, 7, 4], [6, 5]]
Debug
Known issues
gotchaThe `ilp` (Integer Linear Programming) algorithm requires the `pulp` library and an external solver (e.g., CBC, GLPK) to be installed. Without these, using `prtpy.partition.ilp` will result in a `ModuleNotFoundError` for `pulp` or a `PulpSolverError` if no solver is found.
fix
Install `pulp` via `pip install pulp` and ensure a compatible solver (e.g., `cbc` is often included with `pulp` or can be installed separately) is available in your system's PATH.
affects: All versions
gotchaSome partitioning algorithms, such as `prtpy.partition.recursive` and `prtpy.partition.schroeppel`, have exponential time complexity. They are highly efficient for small inputs but can become extremely slow or unresponsive for larger lists of numbers.
fix
For large datasets or performance-critical applications, prefer polynomial-time algorithms like `greedy`, `balancer`, or `complete_greedy`. Consult the documentation for the complexity characteristics of each algorithm.
affects: All versions
gotchaThe `items` argument for partitioning functions expects an iterable of numerical values (integers or floats). Providing non-numerical types (e.g., strings) will lead to `TypeError` or unexpected behavior during comparisons or arithmetic operations.
fix
Always ensure that the list of items you pass to `prtpy` algorithms contains only numbers. Validate or sanitize your input data if it originates from external sources.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pulp'
You are attempting to use the `prtpy.partition.ilp` algorithm without having the `pulp` library installed.
fix
Install the `pulp` library using `pip install pulp`.
TypeError: '<' not supported between instances of 'str' and 'int'
One or more elements in your `items` list are strings (or other non-numeric types) instead of numbers, which `prtpy` algorithms expect.
fix
Ensure all items in the list passed to `prtpy` algorithms are numerical (integers or floats).
Program runs indefinitely or extremely slowly for large inputs.
You are likely using an exponential-time complexity algorithm (e.g., `recursive`, `schroeppel`) with a large number of input items.
fix
Switch to a polynomial-time complexity algorithm for large inputs, such as `greedy`, `balancer`, or `complete_greedy`, which are much more performant.
Upgrade
Version history
0.8.3latest on PyPI · released May 15, 2024
Audit
Dependencies
pulpoptionalRequired for the `ilp` (Integer Linear Programming) partitioning algorithm.
Agent activity
7 hits · last 30 days
node
6
Resources
prtpy — pip install prtpy · libregistry