Skip to main content

pychoco

ubuntu_build macos_build windows_build codecov PyPI version Documentation Status PyPI Downloads License DOI

Current choco-solver version: 6.0.2

Python bindings for the Choco Constraint programming solver (https://choco-solver.org/).

Choco-solver is an open-source Java library for Constraint Programming (see https://choco-solver.org/). It comes with many features such as various types of variables, various state-of-the-art constraint, various search strategies, etc.

The pychoco library uses a native-build of the original Java Choco-solver library, in the form of a shared library, which means that it can be used without any JVM. This native-build is created with GraalVM native-image tool.

We heavily relied on JGraphT Python bindings source code to understand how such a thing could be achieved, so many thanks to JGraphT authors!

Installation

We automatically build 64-bit wheels for Python versions >= 3.10 on Linux (x86_64), Windows (AMD64) and MacOSX (arm64). They can be directly downloaded from PyPI (https://pypi.org/project/pychoco/) or using pip:

pip install pychoco

Documentation

If you do not have any knowledge about Constraint Programming (CP) and Choco-solver, you can have a look at https://choco-solver.org/tutos/ for a quick introduction to CP and to Choco-solver features. The tutorial in this website includes both Java and Python examples. For this Python API, we also provide an API documentation which is available online at https://pychoco.readthedocs.io/.

You can also have a look at the pychoco Cheat Sheet : pychoco cheat sheet

Finally, we designed a few notebooks examples that you can find in the examples directory.

Quickstart

pychoco's API is quite close to Choco's Java API. The first thing to do is to import the library and create a model object:

from pychoco import Model

model = Model("My Choco Model")

Then, you can use this model object to create variables:

intvars = model.intvars(10, 0, 10)
sum_var = model.intvar(0, 100)

You can also create views from this Model object:

b6 = model.int_ge_view(intvars[6], 6)

Create and post (or reify) constraints:

model.all_different(intvars).post()
model.sum(intvars, "=", sum_var).post()
b7 = model.arithm(intvars[7], ">=", 7).reify()

Solve your problem:

model.get_solver().solve()

And retrieve the solution:

print("intvars = {}".format([i.get_value() for i in intvars]))
print("sum = {}".format(sum_var.get_value()))
print("intvar[6] >= 6 ? {}".format(b6.get_value()))
print("intvar[7] >= 7 ? {}".format(b7.get_value()))
> intvars = [3, 5, 9, 6, 7, 2, 0, 1, 4, 8]
> sum = 45
> intvar[6] >= 6 ? False
> intvar[7] >= 7 ? False

Generic search strategies

Currently, the main limitation of pychoco is the customization of search strategies, which is not as advanced as the Java version. This is mainly due to the fact that pychoco's need to rely on a compiled C entrypoint to Choco-solver, which does not allow Python routines to be injected into the solving procedure. One possible solution would be to implement a parsing system to define custom search strategy in Choco-solver, and rely on this system in pychoco. However, this represents a considerable amount of work that we cannot commit to in the short term. Note: please do not hesitate to let us know, or open a pull request if you want to implement this feature, or suggest an alternative solution.

However, it is possible to rely on the generic search heuristics available in Choco-solver, through the Solver object. Currently available search strategies are: default_search, dom_over_w_deg_search, dom_over_w_deg_ref_search, activity_based_search, min_dom_lb_search, min_dom_ub_search, random_search, conflict_history_search, input_order_lb_search, input_order_ub_search, failure_length_based_search, failure_rate_based_search, pick_on_dom_search, pick_on_fil_search.

Example:

solver.set_dom_over_w_deg_search(decision_variables)

Hints

Hints can improve the search procedure by defining a partial solution and drive the search toward a solution. Hints apply on integer variables, and consist of couples of (variable, value).

Example:

solver.add_hint(cost, min_cost)

Parallel portfolio

The parallel portfolio is a powerful feature of Choco-solver which allows to solve a problem in parallel with different search strategies. Each solving thread can inform other when he finds a solution, leading them to update their bounds in case of an optimization process. To set up a parallel portfolio, it is necessary to construct as many identical models as the number of threads. This feature can very efficient to boost the optimization procedure.

Example:

from pychoco.model import Model
from pychoco.parallel_portfolio import ParallelPortfolio

pf = ParallelPortfolio()
pf.steal_nogoods_on_restarts()
for i in range(0, 5):
    m = Model()
    vars = m.intvars(10, 0, 100)
    nv = m.intvar(3, 4)
    m.n_values(vars, nv).post()
    s = m.intvar(0, 1000)
    m.sum(vars, "=", s).post()
    m.set_objective(s, True)
    pf.add_model(m)
sol = pf.find_best_solution()

Build from source

The following system dependencies are required to build pychoco from sources:

Once these dependencies are satisfied, clone the current repository:

git clone --recurse-submodules https://github.com/chocoteam/pychoco.git

The --recurse-submodules is necessary as the choco-solver-capi is a separate git project included as a submodule (see https://github.com/chocoteam/choco-solver-capi). It contains all the necessary to compile Choco-solver as a shared native library using GraalVM native-image.

Ensure that the $JAVA_HOME environment variable is pointing to GraalVM, and from the cloned repository execute the following command:

sh build.sh

This command will compile Choco-solver into a shared native library and compile the Python bindings to this native API using SWIG.

Finally, run:

pip install .

And voilà !

Citation

Justeau-Allaire D, Prud’homme C (2025). pychoco: all-inclusive Python bindings for the Choco-solver constraint programming library. Journal of Open Source Software, 10(113), 8847, https://doi.org/10.21105/joss.08847

Getting help or contribute

We do our best to maintain pychoco and keep it up-to-date with choco-solver. However, if you see missing features, if you have any questions about using the library, suggestions for improvements, or if you detect a bug, please open an issue.

Release files for pychoco 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pychoco 0.4.0
File
pychoco-0.4.0-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
pychoco-0.4.0-cp314-cp314t-manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.34+ x86-64 Details
pychoco-0.4.0-cp314-cp314t-macosx_15_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 15.0+ ARM64 Details
pychoco-0.4.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pychoco-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.34+ x86-64 Details
pychoco-0.4.0-cp314-cp314-macosx_15_0_arm64.whl CPython 3.14 CPython 3.14 macOS 15.0+ ARM64 Details
pychoco-0.4.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pychoco-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details
pychoco-0.4.0-cp313-cp313-macosx_15_0_arm64.whl CPython 3.13 CPython 3.13 macOS 15.0+ ARM64 Details
pychoco-0.4.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pychoco-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
pychoco-0.4.0-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details
pychoco-0.4.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pychoco-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
pychoco-0.4.0-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details
pychoco-0.4.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pychoco-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
pychoco-0.4.0-cp310-cp310-macosx_15_0_arm64.whl CPython 3.10 CPython 3.10 macOS 15.0+ ARM64 Details

Total release size: 291.6 MB

Release files / pychoco-0.4.0-cp314-cp314t-win_amd64.whl

Download URL pychoco-0.4.0-cp314-cp314t-win_amd64.whl
Size 21.6 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
cc05345937234f43be8c0235d2e0dc878cc743dc754163140663a2754a0384ff
BLAKE2b-256 checksum
How to use checksums
a1b616737818032fa919df0246390ba05ddbb2319314e17cbbe5b5fee7238d61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp314-cp314t-manylinux_2_34_x86_64.whl

Download URL pychoco-0.4.0-cp314-cp314t-manylinux_2_34_x86_64.whl
Size 17.6 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
212a8f323b19b02bf0e039378f1749bc1a8254716b8825ea3a9c890ca1f8bfdd
BLAKE2b-256 checksum
How to use checksums
ec6d02cb5ceaac0eae48116f5fc9932928400bbbe1d8f442c67758b4566af9b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp314-cp314t-macosx_15_0_arm64.whl

Download URL pychoco-0.4.0-cp314-cp314t-macosx_15_0_arm64.whl
Size 9.8 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
3e6a0c2e1d5d81ea75aabc5db2242d6370f259d4a5e34d57501191886cf4f065
BLAKE2b-256 checksum
How to use checksums
8478b171035d5fe01948b20f713d495a9517ca58bcb5b10d9bc1d227015094a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp314-cp314-win_amd64.whl

Download URL pychoco-0.4.0-cp314-cp314-win_amd64.whl
Size 21.6 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
5ac6c4eae8bb00c2f403546ba5dea4e2f45fbe99678205dd4105a8892e2c9cbd
BLAKE2b-256 checksum
How to use checksums
b53a2d31eed369256461af5020a71fcf46e034ff4612adffec15649ac3fe2ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl

Download URL pychoco-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl
Size 17.6 MB
Tags CPython 3.14 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
f12811a126d4451d7b06a13fee3ff463dab0442b03e97d75146e45d547c5bdb6
BLAKE2b-256 checksum
How to use checksums
bc97025e91379fa8166779c95ad4b92886bcbcd7e6f05d58839b88d9161ab632
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp314-cp314-macosx_15_0_arm64.whl

Download URL pychoco-0.4.0-cp314-cp314-macosx_15_0_arm64.whl
Size 9.8 MB
Tags CPython 3.14 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
742e23eb92643fa265dd93a5d5961e6836c1f5421a42f82371da90c57ee156c3
BLAKE2b-256 checksum
How to use checksums
c82296b888f225ef0ce1ff10497c0c7567f6ea4b145c883746d88a61107b15c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp313-cp313-win_amd64.whl

Download URL pychoco-0.4.0-cp313-cp313-win_amd64.whl
Size 21.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
25184eae4a54abd5572db47e5a6a8f0fbbddb544f65a7c138ee44376cec30986
BLAKE2b-256 checksum
How to use checksums
49ba88f11b2cf2599ea7c4e4dfcf130fbf90906d8db9132afe42071473b9a6d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL pychoco-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
Size 17.6 MB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
d4bad606044d24b8bfb63ef7b7a12956fece0d5e66018b322e3d45e5d696dbcb
BLAKE2b-256 checksum
How to use checksums
6bf8a5f5f4f39e7b97590423de2b83522e66b9fdc4a527ba166537f5451014da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp313-cp313-macosx_15_0_arm64.whl

Download URL pychoco-0.4.0-cp313-cp313-macosx_15_0_arm64.whl
Size 9.8 MB
Tags CPython 3.13 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
5af747d9a66226e1eeaa9e88f1501fec9a168eda3f7dc1fccf41b7e6e2259a67
BLAKE2b-256 checksum
How to use checksums
81b0073944d356ad080890c8f3d942c7f8131f253f227648eb6e43b9ac946de7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp312-cp312-win_amd64.whl

Download URL pychoco-0.4.0-cp312-cp312-win_amd64.whl
Size 21.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
82036ab62e8f45bff83025da109a7e47a046cfb1ebd07b7e02916e2911f46424
BLAKE2b-256 checksum
How to use checksums
8bce5daa74169baf2fdd09b9813fda5504240b8fb287cf27290402636f9e0c77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL pychoco-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Size 17.6 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
121d89deb37ccb5ec32951d44e4367bf3a9218bda3c5d0b5c5610e605e6ba361
BLAKE2b-256 checksum
How to use checksums
ef9aec361bb2a4bafbac920a29e10da6649d0bdec5849a816af7f5f22ad1ae19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp312-cp312-macosx_15_0_arm64.whl

Download URL pychoco-0.4.0-cp312-cp312-macosx_15_0_arm64.whl
Size 9.8 MB
Tags CPython 3.12 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
a801928de22f3c7752e475dd79f729728f2726a878c8c5de5bae058090200172
BLAKE2b-256 checksum
How to use checksums
dee012880381a7551ffd63e535147c362c922d9550981228499a52dcec93089c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp311-cp311-win_amd64.whl

Download URL pychoco-0.4.0-cp311-cp311-win_amd64.whl
Size 21.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
d5d967c68a87e0dbf308d4fde6a18daa10c0d47958bc0286eb61554a0cb0cdca
BLAKE2b-256 checksum
How to use checksums
b0ca9c44c4aa5a63261f3964b908b65c95a01aa48319e24c7399aaac59005be9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL pychoco-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl
Size 17.6 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
054083591247be1a0ea9378a0c0600dc8009d71009cc9e4174a585c243f720b0
BLAKE2b-256 checksum
How to use checksums
8736a933614030c56ab525e93916b69d5cbcd06faf0d0a8d0be4b02753f6ad87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp311-cp311-macosx_15_0_arm64.whl

Download URL pychoco-0.4.0-cp311-cp311-macosx_15_0_arm64.whl
Size 9.8 MB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
b2132414a8411861b500205ae24a6d43f116f17285e0a725a78b8ee233e0df42
BLAKE2b-256 checksum
How to use checksums
fcb3becc958cc010061ed9519bfaa30093e7683ce5a1c50dc3a994c48f5f64ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp310-cp310-win_amd64.whl

Download URL pychoco-0.4.0-cp310-cp310-win_amd64.whl
Size 21.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
ac43c1bc9c0be5571daf83a3cfc1afc3a772cdb6607663ff7f25584bd85070fc
BLAKE2b-256 checksum
How to use checksums
e48fc6cb6ae84d161b55906e9d3cb92943aed014a4cf07dc864181dc68b11d98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL pychoco-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl
Size 17.6 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
3fef0abde4d2af1d3b5fafd1954a4333aaf696ca409f44fcffe60c2c39bd14f1
BLAKE2b-256 checksum
How to use checksums
8253e52155af26610e6bff3a498527fbb2670ccd58ecef513475106604c42a1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pychoco-0.4.0-cp310-cp310-macosx_15_0_arm64.whl

Download URL pychoco-0.4.0-cp310-cp310-macosx_15_0_arm64.whl
Size 9.8 MB
Tags CPython 3.10 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
291abe216e71d81e977fefefa8b778493751ef4813ab642412a6588a0c954d18
BLAKE2b-256 checksum
How to use checksums
9d75a04dc5dc2d4909273bec9ce18efd6e7a7f95e5fc43e4f6d8e0c0b071848b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.4.0 This release

18 release files

0.2.6

24 release files

0.2.5

18 release files

0.2.4

39 release files

0.2.3

46 release files

0.1.2

16 release files

0.1

14 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page