Interface ¶
Module: lean_interact.interface
This module provides the base classes and data models for interacting with the Lean REPL (Read-Eval-Print Loop). It defines the request and response structures used for sending commands to the Lean server and receiving results. These are aligned with the Lean REPL's API.
InfoTreeOptions ¶
              Bases: str, Enum
Options for InfoTree detail levels.
            full
  
      class-attribute
      instance-attribute
  
¶
    No filtering: include the entire InfoTree (tactic information, term / elaboration information, messages, goal states, traces, etc.).
            tactics
  
      class-attribute
      instance-attribute
  
¶
    Keep only the nodes produced by tactics. Drops unrelated term / elaboration / non-tactic bookkeeping nodes.
            original
  
      class-attribute
      instance-attribute
  
¶
    First keep the tactic-related nodes, then further restrict to the "original" sub‑parts of those tactic nodes (i.e. non-synthetic nodes).
            substantive
  
      class-attribute
      instance-attribute
  
¶
    Keep only the substantive content coming from tactic nodes, removing nodes that are merely a tactic combinator (e.g. by, ;, multiline, parentheses).
CommandOptions ¶
              Bases: REPLBaseModel
Common options for Command and FileCommand.
            all_tactics
  
      class-attribute
      instance-attribute
  
¶
    If true, return all tactics used in the command with their associated information.
            declarations
  
      class-attribute
      instance-attribute
  
¶
    If true, return detailed information about declarations in the command.
            root_goals
  
      class-attribute
      instance-attribute
  
¶
    If true, return root goals, i.e. initial goals of all declarations in the command, even if they already have a proof.
            infotree
  
      class-attribute
      instance-attribute
  
¶
infotree: InfoTreeOptions | str | None = None
Return syntax information. Should be "full", "tactics", "original", or "substantive". Anything else is ignored.
            incrementality
  
      class-attribute
      instance-attribute
  
¶
    If true, enable incremental optimization for the command.
            set_options
  
      class-attribute
      instance-attribute
  
¶
    Options to be set before executing the command (i.e. set_option commands in Lean).
            model_config
  
      class-attribute
      instance-attribute
  
¶
    Command ¶
              Bases: BaseREPLQuery, CommandOptions
Command to be executed in the REPL.
            env
  
      class-attribute
      instance-attribute
  
¶
    The environment to be used. If env = None, starts a new session (in which you can use import).
If env is set, the command is executed in the given environment.
            model_config
  
      class-attribute
      instance-attribute
  
¶
    
            all_tactics
  
      class-attribute
      instance-attribute
  
¶
    If true, return all tactics used in the command with their associated information.
            declarations
  
      class-attribute
      instance-attribute
  
¶
    If true, return detailed information about declarations in the command.
            root_goals
  
      class-attribute
      instance-attribute
  
¶
    If true, return root goals, i.e. initial goals of all declarations in the command, even if they already have a proof.
            infotree
  
      class-attribute
      instance-attribute
  
¶
infotree: InfoTreeOptions | str | None = None
Return syntax information. Should be "full", "tactics", "original", or "substantive". Anything else is ignored.
            incrementality
  
      class-attribute
      instance-attribute
  
¶
    If true, enable incremental optimization for the command.
            set_options
  
      class-attribute
      instance-attribute
  
¶
    Options to be set before executing the command (i.e. set_option commands in Lean).
FileCommand ¶
              Bases: BaseREPLQuery, CommandOptions
Command for file operations in the REPL.
            env
  
      class-attribute
      instance-attribute
  
¶
    The environment to be used. If env = None, starts a new session (in which you can use import).
If env is set, the command is executed in the given environment.
            model_config
  
      class-attribute
      instance-attribute
  
¶
    
            all_tactics
  
      class-attribute
      instance-attribute
  
¶
    If true, return all tactics used in the command with their associated information.
            declarations
  
      class-attribute
      instance-attribute
  
¶
    If true, return detailed information about declarations in the command.
            root_goals
  
      class-attribute
      instance-attribute
  
¶
    If true, return root goals, i.e. initial goals of all declarations in the command, even if they already have a proof.
            infotree
  
      class-attribute
      instance-attribute
  
¶
infotree: InfoTreeOptions | str | None = None
Return syntax information. Should be "full", "tactics", "original", or "substantive". Anything else is ignored.
            incrementality
  
      class-attribute
      instance-attribute
  
¶
    If true, enable incremental optimization for the command.
            set_options
  
      class-attribute
      instance-attribute
  
¶
    Options to be set before executing the command (i.e. set_option commands in Lean).
ProofStep ¶
              Bases: BaseREPLQuery
Proof step in the REPL.
PickleEnvironment ¶
              Bases: BaseREPLQuery
Environment for pickling in the REPL.
UnpickleEnvironment ¶
PickleProofState ¶
              Bases: BaseREPLQuery
Proof state for pickling in the REPL.
UnpickleProofState ¶
              Bases: BaseREPLQuery
Environment for unpickling in the REPL.
CommandResponse ¶
              Bases: BaseREPLResponse
Response to a command in the REPL.
Source code in src/lean_interact/interface.py
                    
                  
            tactics
  
      class-attribute
      instance-attribute
  
¶
tactics: list[Tactic] = Field(default_factory=list)
List of tactics in the code. Returned only if all_tactics is true.
            declarations
  
      class-attribute
      instance-attribute
  
¶
declarations: list[DeclarationInfo] = Field(
    default_factory=list
)
List of declarations in the code. Returned only if declarations is true.
            infotree
  
      class-attribute
      instance-attribute
  
¶
infotree: list[InfoTree] | None = None
The infotree of the code. Returned only if infotree is true.
            model_config
  
      class-attribute
      instance-attribute
  
¶
    
            messages
  
      class-attribute
      instance-attribute
  
¶
messages: list[Message] = Field(default_factory=list)
List of messages in the response.
            sorries
  
      class-attribute
      instance-attribute
  
¶
sorries: list[Sorry] = Field(default_factory=list)
List of sorries found in the submitted code.
has_errors ¶
lean_code_is_valid ¶
lean_code_is_valid(
    start_pos: Pos | None = None,
    end_pos: Pos | None = None,
    allow_sorry: bool = True,
) -> bool
Check if the submitted code is valid Lean code.
Source code in src/lean_interact/interface.py
              ProofStepResponse ¶
              Bases: BaseREPLResponse
Response to a proof step in the REPL.
Source code in src/lean_interact/interface.py
                    
                  
            proof_status
  
      instance-attribute
  
¶
    The proof status of the whole proof. Possible values: Completed, Incomplete, Error.
It may contain additional information, e.g. Incomplete: contains sorry.
            goals
  
      class-attribute
      instance-attribute
  
¶
    List of goals after the proof step.
            traces
  
      class-attribute
      instance-attribute
  
¶
    List of traces in the proof step.
            model_config
  
      class-attribute
      instance-attribute
  
¶
    
            messages
  
      class-attribute
      instance-attribute
  
¶
messages: list[Message] = Field(default_factory=list)
List of messages in the response.
            sorries
  
      class-attribute
      instance-attribute
  
¶
sorries: list[Sorry] = Field(default_factory=list)
List of sorries found in the submitted code.
has_errors ¶
lean_code_is_valid ¶
lean_code_is_valid(
    start_pos: Pos | None = None,
    end_pos: Pos | None = None,
    allow_sorry: bool = True,
) -> bool
Check if the submitted code is valid Lean code.
Source code in src/lean_interact/interface.py
              LeanError ¶
Message ¶
              Bases: REPLBaseModel
Message in the REPL.
Pos ¶
              Bases: REPLBaseModel
Position in the Lean code.
Range ¶
Sorry ¶
              Bases: REPLBaseModel
Sorry message in the REPL.
            start_pos
  
      class-attribute
      instance-attribute
  
¶
start_pos: Pos | None = None
The starting position of the sorry message.
            end_pos
  
      class-attribute
      instance-attribute
  
¶
end_pos: Pos | None = None
The ending position of the sorry message.
            proof_state
  
      class-attribute
      instance-attribute
  
¶
    The proof state associated to the sorry.
            model_config
  
      class-attribute
      instance-attribute
  
¶
    Tactic ¶
InfoTree ¶
              Bases: REPLBaseModel
An InfoTree representation of the Lean code.
            node
  
      instance-attribute
  
¶
    The root node of the InfoTree, which can be a TacticNode, CommandNode, TermNode, or None.
            kind
  
      instance-attribute
  
¶
kind: Literal[
    "TacticInfo",
    "TermInfo",
    "PartialTermInfo",
    "CommandInfo",
    "MacroExpansionInfo",
    "OptionInfo",
    "FieldInfo",
    "CompletionInfo",
    "UserWidgetInfo",
    "CustomInfo",
    "FVarAliasInfo",
    "FieldRedeclInfo",
    "ChoiceInfo",
    "DelabTermInfo",
]
The kind of the InfoTree.
            children
  
      class-attribute
      instance-attribute
  
¶
    Children of the InfoTree, which are also InfoTrees.
            model_config
  
      class-attribute
      instance-attribute
  
¶
    dfs_walk ¶
Walk the InfoTree using Depth-First-Search.
Returns:
| Type | Description | 
|---|---|
| None | Yields the subsequent InfoTree. | 
Source code in src/lean_interact/interface.py
              leaves ¶
Get the InfoTree leaves of the Depth-First-Search
Returns:
| Type | Description | 
|---|---|
| None | Yield the leaves of the InfoTree. | 
commands ¶
Get all InfoTrees that represent commands
Returns:
| Type | Description | 
|---|---|
| None | Yields the command nodes of the InfoTree. | 
Source code in src/lean_interact/interface.py
              variables ¶
Get children corresponding to variable expressions.
Returns:
| Type | Description | 
|---|---|
| None | Yields the variable nodes of the InfoTree. | 
Source code in src/lean_interact/interface.py
              theorems ¶
Get children corresponding to theorems (including lemmas).
Returns:
| Type | Description | 
|---|---|
| None | Yields the theorems of the InfoTree. | 
Source code in src/lean_interact/interface.py
              docs ¶
Get children corresponding to DocStrings.
Returns:
| Type | Description | 
|---|---|
| None | Yields the InfoTree nodes representing Docstrings. | 
Source code in src/lean_interact/interface.py
              namespaces ¶
Get children corresponding to namespaces.
Returns:
| Type | Description | 
|---|---|
| None | Yields the InfoTree nodes for namespaces. | 
Source code in src/lean_interact/interface.py
              pp_up_to ¶
pp_up_to(end_pos: Pos) -> str
Get the pretty-printed string of the InfoTree up to a given position.
Source code in src/lean_interact/interface.py
              theorem_for_sorry ¶
theorem_for_sorry(sorry: Sorry) -> Self | None
Get the theorem InfoTree for a given sorry, if found in this tree.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| sorry | Sorry | The sorry to search a theorem for | required | 
Returns:
| Type | Description | 
|---|---|
| Self | None | The found InfoTree, if found, else None | 
Source code in src/lean_interact/interface.py
              TacticNode ¶
CommandNode ¶
              Bases: BaseNode
A command node of the InfoTree.
TermNode ¶
              Bases: BaseNode
A term node of the InfoTree.
            is_binder
  
      class-attribute
      instance-attribute
  
¶
    Whether the node is a binder or not.
            expected_type
  
      class-attribute
      instance-attribute
  
¶
    The expected type of the term node, if available.
            elaborator
  
      instance-attribute
  
¶
    The elaborator used for the term node, if available.
            model_config
  
      class-attribute
      instance-attribute
  
¶
    Syntax ¶
DocString ¶
DeclModifiers ¶
DeclSignature ¶
BinderView ¶
DeclBinders ¶
              Bases: REPLBaseModel