python-constraint
python-constraint is a module implementing support for handling CSPs (Constraint Solving Problems) over finite domain
What it is and what it does
python-constraint is a pure-Python library for solving constraint satisfaction problems—computational puzzles where you define variables with possible values (domains) and rules (constraints) that those values must satisfy. You create a Problem object, add variables and their allowed values, specify constraints like "a must not equal b" or "a times 2 must equal b", and ask the solver to find all valid assignments. It includes three solver strategies (backtracking, recursive backtracking, and minimum conflicts) and predefined constraint types for common patterns like all-different, exact sums, and set membership.
The library is useful for logic puzzles, scheduling, configuration problems, and other combinatorial search tasks where you need to explore a solution space systematically. It has no external dependencies and runs in standard Python, making it portable and easy to embed. However, the package has not been released in over five years, and while the repository shows recent activity, this stale release cycle creates uncertainty about compatibility with current Python versions and whether bug fixes or improvements have been made but not published.
Use it for:
- Solve logic puzzles like N-queens, magic squares, or sudoku by encoding variables, domains, and constraints.
- Schedule tasks or resources with conflicting requirements by modeling availability and constraints.
- Generate valid configurations for systems where certain combinations of settings are forbidden or required.
- Verify that a set of rules or constraints is satisfiable and enumerate all valid solutions.
- Prototype constraint-based problem solvers before moving to specialized or compiled CSP libraries.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Solves constraint satisfaction problems (CSPs) over finite domains using pure Python, allowing you to define variables, domains, and constraints and retrieve all valid solutions.
Yes, with conditions. The library is actively maintained (recent commits) and solves a real problem with no external dependencies, but the stale release cycle (last version 2018-11-05) creates risk: you may encounter Python compatibility issues or undocumented bugs. Install it if you need a lightweight pure-Python CSP solver for prototyping or small-scale problems and are willing to test thoroughly or patch locally if needed. For production use or large-scale constraint solving, consider whether a more actively released alternative is available.
Install
python-constraint on PyPI
pip
pip install python-constraintuv
uv add python-constraintpoetry
poetry add python-constraintInstalling python-constraint
Before you install
High install friction: the package has not been released since 2018-11-05, and the last commit is recent (2026-08-14), suggesting maintenance activity but no new version published. Installation may encounter compatibility issues with modern Python environments.
License in practice
Permissive BSD license allows use in most projects without significant restrictions, though the exact license text is not specified in the metadata.
Quickstart
from constraint import Problem, AllDifferentConstraint
problem = Problem()
problem.addVariable("a", [1, 2, 3])
problem.addVariable("b", [4, 5, 6])
solutions = problem.getSolutions()
Package has not been released since 2018-11-05; compatibility with modern Python versions (3.7+) is not guaranteed despite active repository maintenance.
Verify before relying
- Whether the package actually supports Python 3.7+ despite classifiers only listing up to 3.6
- Current state of unit test coverage and whether 'Improve code coverage' roadmap item has been completed
- Performance characteristics and scalability limits for large CSP instances
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | actively maintained — 2,839 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 309,876/month — #7,750 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python-constraint-1.4.0.tar.bz2
Keywords: csp, constraint, solving, problems, problem, solver
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
clingoClingo is a Python binding to the clingo Answer…
permissive · top 15,000 on PyPI
pycosatProvides efficient Python bindings to PicoSAT,…
permissive · top 15,000 on PyPI
claripyClaripy is an abstraction layer for constraint…
permissive · top 5,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
python-satPySAT wraps modern Boolean satisfiability…
permissive · top 15,000 on PyPI
cvc5cvc5 is a satisfiability modulo theories (SMT)…
unclear · top 15,000 on PyPI
ortoolsOR-Tools provides constraint programming,…
permissive · top 5,000 on PyPI
qpsolversProvides a unified Python interface to solve…
copyleft · top 5,000 on PyPI
nab-resolverA generic PubGrub-style dependency resolver…
permissive · top 15,000 on PyPI
pyperplanPyperplan is a lightweight STRIPS planner that…
copyleft · top 15,000 on PyPI