leanelpi (Python)
Run ELPI (λProlog) programs on the LeanElpi engine from Python. Needs libleanelpi; build it
with scripts/build-ffi.sh and point LEANELPI_LIB at it, or leave it in dist/.
from leanelpi import Program
p = Program("pred n o:int.\nn 1.\nn 2.")
[s["X"] for s in p.solve("n X")] # ['1', '2']
[s.terms["X"] for s in p.solve("n X")] # [1, 2]
Solution.bindings (and solution["X"]) hold the values as ELPI prints them;
Solution.terms holds them as Python values: int, float, str, a list for an ELPI list,
Const("anna"), App("pt", (1, "x")), Var(name) for an unbound variable and
Opaque(printed) for anything else (λ-terms).
Host predicates (0.4)
declare makes a predicate whose calls Python answers during solve_host, so rules can ask
an LLM or a tool and still decide the conclusion themselves:
from leanelpi import Program, Const, ElpiError
world = Program("""
kind person type.
type anna, marco person.
pred knows i:person, i:person.
knows anna marco.
pred same_person i:string, o:person.
pred believable i:string, i:string.
believable A B :- same_person A PA, same_person B PB, knows PA PB.
""").declare("pred same_person i:string, o:person.")
def same_person(name): # an LLM or a tool would go here
return [Const(c) for c in {"Anya": ["anna"], "Marko": ["marco"]}.get(name, [])]
world.solve_host('believable "Anya" "Marko"', {"same_person": same_person}) # one solution
world.first_host('same_person "Anya" P', {"same_person": same_person}).terms # {'P': Const('anna')}
world.solve_host('believable "Anya" "Marko"', {"same_person": lambda n: [Const("maria")]})
# ElpiError: host predicate 'same_person': unknown constant 'maria'
Program.declare(signature, name=None)returns a new program (the old one is unchanged). The program may already declare the predicate, so its rules can call it, but must not have clauses for it. Querying it with plainsolveraisesElpiError.Program.solve_host(query, host, *, limit=None, fuel=None)returns the solutions;solve_host_allreturns aHostRun(solutions, exhausted, fuel_used)andfirst_hostthe firstSolutionorNone.hostis a dict{name: function}, where the function receives thei:arguments as Python values, or one functionhost(name, args)receiving every argument (unbound ones asVar). It returns an iterable of rows, one tuple ofo:values per answer, in order (a bare value is a one-output row; wrap a list output as([1, 2],)). An empty iterable orNonemeans the call fails;Truemeans it succeeds once (a predicate with no outputs). Returnint,float,str,bool(tt/ff),Const,Appor a list.- An exception in the host stops the run and raises
ElpiErrorwith the exception as__cause__; nothing unwinds through C.KeyboardInterruptandSystemExitare re-raised. - The engine rejects a constant the program does not know. It does not type-check host
answers, so the binding rejects values that cannot have the declared type (a
strforo:person, a constant declared as another kind) and turns anintforo:floatinto a float. - Calls are synchronous, on the thread that called
solve_host; a host may call the engine again, and several threads may runsolve_hostat once.ElpiError.out_of_fueltells a spentfuel=budget from other errors.
See the guide.
Metadata
Release files for leanelpi 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| leanelpi-0.4.1-py3-none-manylinux_2_35_x86_64.whl | Python 3 | none | Linux glibc 2.35+ x86-64 | Details for leanelpi-0.4.1-py3-none-manylinux_2_35_x86_64.whl |
| leanelpi-0.4.1-py3-none-manylinux_2_35_aarch64.whl | Python 3 | none | Linux glibc 2.35+ ARM64 | Details for leanelpi-0.4.1-py3-none-manylinux_2_35_aarch64.whl |
| leanelpi-0.4.1-py3-none-macosx_11_0_x86_64.whl | Python 3 | none | macOS 11.0+ x86-64 | Details for leanelpi-0.4.1-py3-none-macosx_11_0_x86_64.whl |
| leanelpi-0.4.1-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for leanelpi-0.4.1-py3-none-macosx_11_0_arm64.whl |
Total release size: 211.8 MB
Release files / leanelpi-0.4.1-py3-none-manylinux_2_35_x86_64.whl
| Download URL | leanelpi-0.4.1-py3-none-manylinux_2_35_x86_64.whl |
|---|---|
| Size | 57.8 MB |
| Tags | Linux glibc 2.35+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
852db5b51c8069be7e20d2de1d38a098e1ae309cb43b7efd84a43ee009dce556
|
|
BLAKE2b-256 checksum How to use checksums |
247188029284c2e9ff090d3c9f44928e815d977cdbbee4ceb2ca706dfc2d539d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / leanelpi-0.4.1-py3-none-manylinux_2_35_aarch64.whl
| Download URL | leanelpi-0.4.1-py3-none-manylinux_2_35_aarch64.whl |
|---|---|
| Size | 59.8 MB |
| Tags | Linux glibc 2.35+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
d4507f45a74ff684d5da25a22df127f66e5cab4aba1d619a9e7111a43e89b052
|
|
BLAKE2b-256 checksum How to use checksums |
9f12d5f68684b5a4a1021ec01a35bbfb3dbbcdfac9dc0b2d98bc18e23eaeb44c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / leanelpi-0.4.1-py3-none-macosx_11_0_x86_64.whl
| Download URL | leanelpi-0.4.1-py3-none-macosx_11_0_x86_64.whl |
|---|---|
| Size | 49.1 MB |
| Tags | Python 3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
f72382c50d2644a1e280bd46609ade07e778af2c7eed6c59d07d8ef0c6a90ae7
|
|
BLAKE2b-256 checksum How to use checksums |
d12c69f1e4cd6d24cae8a5f36cea9cb22da046d1945657aeeaac9ef31e3d1713
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / leanelpi-0.4.1-py3-none-macosx_11_0_arm64.whl
| Download URL | leanelpi-0.4.1-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 45.0 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fe8b3f3ec80a5e86627a474a4a0585f1b74bd0574bd9429120a33b5f5d3bab75
|
|
BLAKE2b-256 checksum How to use checksums |
1bbb5eca87c1d04f24eecad21136113c14802e9980bc86bca5a159f66c80e8c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for leanelpi 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for leanelpi-0.4.1-py3-none-manylinux_2_35_x86_64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.