Registry / ai-ml / clingo

clingo

JSON →
library5.8.0pypypi✓ verified 86d ago

CFFI-based Python bindings to the clingo Answer Set Programming (ASP) solver. Version 5.8.0, released 2024-04-06. Cadence: irregular, roughly annual.

pip install clingo
INSTALL
IMPORT
SIG · CLINGO
C
clingo
ai-mlpythonv5.8.0
Install
2.0s avg
Import
36ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.8.0 · 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
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.036s · 29.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.0s · import 0.036s · 26MB
26MB installed
● package 26MB
Code
Verified usage

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

Control
from clingo import Control
import clingo; ctl = clingo.Control()
Direct class import is conventional.
Function
from clingo import Function
from clingo.symbol import Function
Function is in clingo, not a submodule.

Basic ASP solving: add rules, ground, and iterate over stable models.

from clingo import Control ctl = Control() ctl.add("base", [], "a :- not b. b :- not a.") ctl.ground([("base", [])]) with ctl.solve(yield_=True) as handle: for model in handle: print(model)
clingo --version
Debug
Known issues
breakingFrom clingo 5.5 to 5.6, the `solve` method changed from returning a `SolveResult` to a `SolveHandle` with a context manager. In 5.4 and earlier, `ctl.solve()` returned a `SolveResult` directly.
fix
Use the context manager: `with ctl.solve(yield_=True) as handle:` instead of `result = ctl.solve()`.
affects: >=5.6
breakingThe `clingo.solving.SolveResult` class was removed in 5.6. `solve()` now returns a `SolveHandle`, and the satisfiability is obtained via `solve()`'s return value after the context manager exits.
fix
After the `with` block, use `handle.get()` to get satisfiability (e.g., `print(handle.get().satisfiable)`).
affects: >=5.6
deprecatedThe `clingo.Control.load()` method is deprecated in 5.8 in favor of `Control.add()` + `Control.ground()`.
fix
Replace `ctl.load('file.lp')` with `with open('file.lp') as f: ctl.add('base', [], f.read()); ctl.ground([('base', [])])`.
affects: 5.8
gotchaCalling `Control.solve()` without `yield_=True` will not return models; you must iterate over the `SolveHandle` or use the context manager with `yield_=True`.
fix
Always use `with ctl.solve(yield_=True) as handle: for model in handle: print(model)`.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'clingo'
Clingo installed from PyPI may not work on systems without a compatible C compiler or prebuilt wheel (e.g., ARM macOS).
fix
Install via conda: `conda install -c potassco clingo`, or install from source with proper dependencies.
clingo.core.SolveError: undefined arithmetic operation
Using arithmetic expressions on ungrounded variables (e.g., `X = Y + 1`) without proper grounding.
fix
Use `#const` directives, or ground the program properly, or avoid arithmetic on variables without domain bounds.
Upgrade
Version history
5.8.0latest on PyPI · released Apr 3, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
clingo — pip install clingo · libregistry