{"library":"python-constraint","title":"Python Constraint","description":"python-constraint is a module implementing support for handling Constraint Satisfaction Problems (CSPs) over finite domains. The current version, 2.5.0, offers enhanced features like efficient string-based constraints, negative value support, and performance improvements, with releases typically occurring several times a year.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install python-constraint"],"cli":null},"imports":["from constraint import Problem","from constraint import Constraint","from constraint import *"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from constraint import Problem\n\nproblem = Problem()\n\n# Add variables with finite domains\nproblem.addVariable('x', [1, 2, 3])\nproblem.addVariable('y', [1, 2, 3])\n\n# Add a string-based constraint (preferred method since v2.1.0)\n# x * 2 == y\nproblem.addConstraint('x * 2 == y', ('x', 'y'))\n\n# Find and print all solutions\nsolutions = problem.getSolutions()\n\n# Example of printing solutions\nif solutions:\n    print(f\"Found {len(solutions)} solution(s):\")\n    for sol in solutions:\n        print(sol)\nelse:\n    print(\"No solutions found.\")","lang":"python","description":"This quickstart demonstrates how to define a simple Constraint Satisfaction Problem (CSP) using the `Problem` class, add variables with their respective finite domains, and apply a string-based constraint. Finally, it shows how to retrieve and iterate through all valid solutions.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}