HTTP Server¶
Run a local HTTP server that provides the same API as the remote Lean Explore service.
Starting the Server¶
Using API Backend¶
This starts a server that proxies requests to the remote API.
Using Local Backend¶
# First, fetch local data
leanexplore data fetch
# Start server with local backend
leanexplore http serve --backend local
Custom Configuration¶
API Endpoints¶
The server provides the same endpoints as the remote API:
Search¶
Parameters:
- q (required): Search query string
- pkg (optional): Package filter (can be specified multiple times)
Example:
Response:
{
"query": "natural numbers",
"results": [
{
"id": 123,
"primary_declaration": {
"lean_name": "Nat"
},
"informal_description": "..."
}
]
}
Get Dependencies¶
Example:
Response:
{
"source_group_id": 123,
"citations": [
{
"id": 456,
"primary_declaration": {
"lean_name": "Nat.add"
}
}
],
"count": 1
}
Using with Python Client¶
You can use the Python client with a local server:
from lean_explore.api.client import Client
# Connect to local server
client = Client(base_url="http://localhost:8001")
# Use as normal
results = await client.search("natural numbers")
OpenAPI Documentation¶
The server provides OpenAPI documentation at:
- Swagger UI:
http://localhost:8001/docs - ReDoc:
http://localhost:8001/redoc - OpenAPI JSON:
http://localhost:8001/openapi.json
Backend Comparison¶
API Backend¶
- Pros: No local data required, always up-to-date
- Cons: Requires API key, network access needed
Local Backend¶
- Pros: No API key needed, works offline, faster for repeated queries
- Cons: Requires local data download, may be out of date
Next Steps¶
- CLI Usage - Command-line interface
- API Client - Python API client
- MCP Server - Model Context Protocol server