Skip to main content

A Python client for the Lean Theorem Prover Server API.

Project description

Lean Client

A Python client for the Lean Server API.

This package provides a simple, asynchronous LeanClient to interact with the lean-server.

📦 Installation

As a Standalone Package

To install this package from PyPI (once published):

pip install lean-client

For Development

This package is part of a monorepo. For development, follow the setup instructions in the root README. The recommended installation command within the dev container is:

# This installs the client in editable mode
uv pip install -e .

🚀 Usage

The client is asynchronous and designed to be used with asyncio.

Basic Usage

Here is a basic usage example:

import asyncio
from lean_runner import LeanClient

async def main():
    # Assumes the server is running on http://localhost:8000
    # The client can be used as an async context manager.
    async with LeanClient("http://localhost:8000") as client:
        proof_to_check = "def my_theorem : 1 + 1 = 2 := rfl"

        # Optional configuration can be passed as a dictionary.
        config = {"timeout": 60}

        print(f"Checking proof: '{proof_to_check}'")
        result = await client.check_proof(proof_to_check, config=config)

        print("\nServer response:")
        print(result)

if __name__ == "__main__":
    # To run the example, save it as a file (e.g., `test_client.py`)
    # and run `python test_client.py` in a terminal where the server is running.
    asyncio.run(main())

File Support

The client supports multiple ways to provide proof content:

  1. String content directly:
proof_content = "theorem test : 1 + 1 = 2 := by rfl"
result = await client.check_proof(proof_content)
  1. File path as string:
result = await client.check_proof("path/to/proof.lean")
  1. Path object:
from pathlib import Path
proof_file = Path("path/to/proof.lean")
result = await client.check_proof(proof_file)

Complete Example with File

import asyncio
from pathlib import Path
from lean_runner import LeanClient

async def check_proof_from_file():
    async with LeanClient("http://localhost:8000") as client:
        # Create a test Lean file
        proof_file = Path("test_proof.lean")
        proof_content = """
theorem test_theorem : 1 + 1 = 2 := by
  rw [add_comm]
  rw [add_zero]
  rfl
"""

        # Write content to file
        with open(proof_file, 'w', encoding='utf-8') as f:
            f.write(proof_content)

        try:
            # Check proof from file
            result = await client.check_proof(proof_file, config={"timeout": 30})
            print(f"Proof check result: {result}")
        finally:
            # Clean up
            if proof_file.exists():
                proof_file.unlink()

if __name__ == "__main__":
    asyncio.run(check_proof_from_file())

📚 API Reference

LeanClient

The main client class for interacting with the Lean Server.

__init__(base_url: str)

Initialize the client with the server's base URL.

async check_proof(proof: Union[str, Path, os.PathLike], config: dict[str, Any] | None = None) -> dict[str, Any]

Send a proof to the server for checking.

Parameters:

  • proof: The proof content. Can be:
    • A string containing the proof
    • A Path object pointing to a file containing the proof
    • A string path to a file containing the proof
  • config: Optional configuration dictionary for the proof check

Returns:

  • A dictionary containing the server's response

async close()

Close the client session.

async __aenter__() and async __aexit__()

Async context manager support for automatic session management.

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_runner-0.2.0.dev1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

lean_runner-0.2.0.dev1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file lean_runner-0.2.0.dev1.tar.gz.

File metadata

  • Download URL: lean_runner-0.2.0.dev1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for lean_runner-0.2.0.dev1.tar.gz
Algorithm Hash digest
SHA256 b074f4a9fd8db8fd722141d5fea94fe6d8e87250d7a5696224fb77fbce8e0f63
MD5 48a06d8c1702f0b40463e62001ca4288
BLAKE2b-256 b7edc0c70a1d0f633600b5cb02754a43f841927d03fd22c94e93c32a11c701e6

See more details on using hashes here.

File details

Details for the file lean_runner-0.2.0.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for lean_runner-0.2.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 78ca247cd01bafaec1f2ef45ac72ce012e8191fdb023e384f03e823b61a55131
MD5 0bd88483463638b3d5f4d0bfdef3b313
BLAKE2b-256 bdd91e7ce2f37238ac097757180a22fdfb84aceb28a5a8b5d5a407ec876288c7

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