clingo.core

Core functionality used throughout the clingo package.

Examples

>>> from clingo.core import version
>>> version()
(6, 0, 0)
class Library:

A library object that manages Clingo's core resources.

This object is responsible for storing the logger, symbols, strings, and scripts. Functions and classes that need to create symbols require an instance of this class.

This class implements the ContextManager interface.

Library( shared: bool = True, slotted: bool = True, log_level: LogLevel = <LogLevel.Info: 2>, logger: Callable[[MessageType, str], None] | None = None, message_limit: int = 25)

Create a library object.

Arguments:
  • slotted: Use a slotted allocator to store symbols. Setting this to true might improve performance.
  • shared: Indicates whether symbols should be created in a thread-safe manner. Setting this to false might improve performance in single-threaded applications.
  • log_level: The log level.
  • logger: A logger to emit/intercept messages.
  • message_limit: The maximum number of messages to emit.
class Location:

Represents a range of positions in a source file.

The Location object tracks the start and end positions of a region in the file. It is used for error reporting and debugging, providing information about the source of the program elements.

Location(begin: Position, end: Position)

Create a location object.

Arguments:
  • begin: The beginning of the location.
  • end: The end of the location.
begin: Position

The beginning of the location.

end: Position

The end of the location.

class LogLevel(enum.IntEnum):

The available log levels.

Debug = <LogLevel.Debug: 1>
Error = <LogLevel.Error: 8>
Info = <LogLevel.Info: 2>
Trace = <LogLevel.Trace: 0>
Warn = <LogLevel.Warn: 7>
class MessageType(enum.IntEnum):

Message categories emitted by the logger.

AtomUndefined = <MessageType.AtomUndefined: 4>
Debug = <MessageType.Debug: 1>
Error = <MessageType.Error: 8>
FileIncluded = <MessageType.FileIncluded: 5>
GlobalVariable = <MessageType.GlobalVariable: 6>
Info = <MessageType.Info: 2>
OperationUndefined = <MessageType.OperationUndefined: 3>
Trace = <MessageType.Trace: 0>
Warn = <MessageType.Warn: 7>
class Position:

Represents a position in a source file.

A Position object tracks the location of a symbol or construct within a source file, including its file name, line number, and column.

Position(lib: Library, file: str, line: int, column: int)

Create a position object.

Arguments:
  • lib: The library object managing symbols.
  • file: The file name where the position is located.
  • line: The line number in the file.
  • column: The column number in the line.
column: int

The column number.

file: str

The file name.

line: int

The line number.

def version() -> tuple[int, int, int]:

Get Clingo's version.

Returns:

A tuple (major, minor, revision) representing the Clingo version.