Skip to main content

A Python application to interact with the Lean REPL.

Project description

lean-repl-py

lean-repl-py is a Python application designed to interact with the Lean REPL (Read-Eval-Print Loop). It provides an interface for sending commands to Lean and processing responses, making it easier to automate theorem proving using Python.

Features

  • Simple Interface: Send Lean commands and receive responses seamlessly.
  • Automation: Useful for scripting Lean interactions programmatically.
  • No Dependencies: A lightweight tool with zero external dependencies.
  • Fast: Adds no noticeable overhead on top of the lean REPL.

Installation

You can install lean-repl-py via PyPI:

pip install lean-repl-py

Prerequisites

Requires lake to be available on your system. That's it, no more strings attached.

Importantly, lean-repl-py ships with the correct version of the lean repl, so it is not needed separately.

Important notices

The first start in a new python environment will take some time, as the repl must be built first.

Usage

from lean_repl_py import LeanREPLHandler, LeanREPLPos, LeanREPLEnvironment, LeanREPLProofState, LeanREPLMessage
from pathlib import Path


# Create a new Lean REPL handler
lean_repl = LeanREPLHandler()

# Optionally, use the REPL from another project for dependencies
# This is needed e.g. if you want to use mathlib.
lean_repl = LeanREPLHandler(project_path=Path("path/to/your/leanproject"))

## Send a command to Lean
lean_repl.send_command("def f := 2")
response, env = lean_repl.receive_json()
# Env will be a LeanREPLEnvironment object, which contains the environment index
LeanREPLEnvironment(env_index=0)
# Response will be a dictionary with the Lean REPL response apart from the environment
{}

## Use an environment for subsequent commands
lean_repl.env = env.env_index
lean_repl.send_command("def g := f + 2") # Will use the previous environment
_ = lean_repl.receive_json()

## Use tactic mode
lean_repl.send_command("def h (x : Unit) : Nat := by sorry")
response, env = lean_repl.receive_json()
# Will return proof state objects LeanREPLProofState
LeanREPLProofState(goal="x : Unit\n⊢ Nat", proof_state=0, pos=LeanREPLPos(line=1, column=29), end_pos=LeanREPLPos(line=1, column=34))
# And messages
LeanREPLMessage(message="declaration uses 'sorry'", severity="warning", pos=LeanREPLPos(line=1, column=4), end_pos=LeanREPLPos(line=1, column=5))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lean_repl_py-0.1.7.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lean_repl_py-0.1.7-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file lean_repl_py-0.1.7.tar.gz.

File metadata

  • Download URL: lean_repl_py-0.1.7.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0.dev0 CPython/3.9.20 Linux/6.5.0-1025-azure

File hashes

Hashes for lean_repl_py-0.1.7.tar.gz
Algorithm Hash digest
SHA256 9a55b6994d22dc625df7b90bf832a342058324ed662bfe2d5dfa1b62c30a2dec
MD5 19809520512f234fb864c4ce5d01815f
BLAKE2b-256 416773c966da0f31407e0091ff7136e47b81cd42dfbcc82ca46a4c2547d1a8fc

See more details on using hashes here.

File details

Details for the file lean_repl_py-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: lean_repl_py-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0.dev0 CPython/3.9.20 Linux/6.5.0-1025-azure

File hashes

Hashes for lean_repl_py-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d657ec4deb1f9706af54feb5348c4e85da4fa61891836df580ef6c7a051432c2
MD5 9d07ebb198727921916b7f6f9d5caf7c
BLAKE2b-256 1075db3ccd7d7f20c17c65b62e0c2660439a6f6f0e5b1ffb11341f42cc181ea4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page