skillfed

python-constraint

python-constraint is a module implementing support for handling CSPs (Constraint Solving Problems) over finite domain

python-constraint v1.4.0 309.9K downloads/30d#7,750 on PyPI515
Permissive license Active released

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-constraint

uv

uv add python-constraint

poetry

poetry add python-constraint

Installing 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

Development Status :: 3 - AlphaEnvironment :: ConsoleIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: CythonProgramming Language :: PythonProgramming Language :: Python :: 2.7Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Topic :: Scientific/Engineering

Tags

constraint satisfaction problem solverCSP solver pythonfinite domain constraint solvingbacktracking constraint solverlogic puzzle solver
constraint-solvinglogic-puzzlescombinatorial-search

More Scientific/Engineering packages