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, logger: Optional[Callable[[MessageType, str], NoneType]] = 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:

The available log levels.

LogLevel(value: int)
Debug: ClassVar[LogLevel] = LogLevel.Debug

Report debug messages (includes info level).

Error: ClassVar[LogLevel] = LogLevel.Error

Report error messages.

Info: ClassVar[LogLevel] = LogLevel.Info

Report info messages (includes warning level).

Trace: ClassVar[LogLevel] = LogLevel.Trace

Report trace messages (includes debug level).

Warn: ClassVar[LogLevel] = LogLevel.Warn

Report warning messages (includes error level).

name: str
value: int
class MessageType:

Message categories emitted by the logger.

MessageType(value: int)
AtomUndefined: ClassVar[MessageType] = MessageType.AtomUndefined

An info message about an undefined atom.

Debug: ClassVar[MessageType] = MessageType.Debug

A debug message.

Error: ClassVar[MessageType] = MessageType.Error

An error message.

FileIncluded: ClassVar[MessageType] = MessageType.FileIncluded

An info message about an already included file.

GlobalVariable: ClassVar[MessageType] = MessageType.GlobalVariable

An info message about a global variable in the tuple of an aggregate.

Info: ClassVar[MessageType] = MessageType.Info

A generic info message.

OperationUndefined: ClassVar[MessageType] = MessageType.OperationUndefined

An info message about an undefined operation.

Trace: ClassVar[MessageType] = MessageType.Trace

A trace message.

Warn: ClassVar[MessageType] = MessageType.Warn

A warning message.

name: str
value: int
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.