Skip to main content

InferLingo

InferLingo is a small Python rule engine for facts and rules written as readable sentences. Use deterministic code to establish facts, InferLingo to derive consequences from explicit rules, and optional semantic unification when differently worded sentences may express the same fact.

InferLingo is not a chatbot, planner, arithmetic engine, source-code analyzer, or action runner. Python or another deterministic subsystem supplies facts. InferLingo applies the rules you write, builds inspectable proofs, and returns derived consequences.

Install

Install the base package for deterministic inference:

python -m pip install inferlingo

The base package is fully usable offline. The Python KnowledgeBase API defaults to ExactUnifier, and the first CLI workflows should use --exact-only.

Install the optional semantic backend only when differently worded sentences should be compared:

python -m pip install 'inferlingo[jev]'

Authentication and provider configuration belong to pyjev and its configured Jev backend.

60-second exact example

Create rules.nl:

Alice is an employee.
Bob is an employee.
Bob is suspended.

{person} may deploy if
    {person} is an employee and
    not {person} is suspended.

Run it without a model or network access:

inferlingo run rules.nl "{person} may deploy?" --exact-only --explain

The solution binds person = Alice. The result follows only from the facts and explicit rule. Negation is failure to prove the positive goal for the already-bound person, not a stored classical negative fact.

The smallest chain is also available:

inferlingo run examples/birds.nl "{bird} can fly?" --exact-only --explain

It derives bird = Tweety from the fact and rules in examples/birds.nl, not from outside knowledge.

How it fits into Python

from inferlingo import KnowledgeBase

kb = KnowledgeBase.from_text(
    """
    Alice is an employee.
    {person} may deploy if {person} is an employee.
    """
)
result = kb.ask_sync("{person} may deploy?")
print(result.solutions[0].bindings)

The result is {"person": "Alice"}. Use await kb.ask(...) in asynchronous applications. ask_sync() must not be called from a running event loop.

KnowledgeBase.add_fact() safely quotes injected application values and can carry Provenance metadata into proof steps:

from inferlingo import KnowledgeBase, Provenance

kb = KnowledgeBase.from_text("URL {url} is approved if URL {url} is reachable.")
kb.add_fact(
    "URL {url} is reachable",
    url="https://example.com/a?x=1&y=2",
    provenance=Provenance(source="scanner.py", line=41, kind="http-check"),
)

Optional semantic unification

PyJevUnifier first tries exact wording and only sends differently worded candidates to the semantic backend. Semantic matching is a same-fact equivalence check. It does not invent logical implications. An explicit rule is still required to derive parent from father.

python -m pip install 'inferlingo[jev]'
pyjev auth set
pyjev auth test
inferlingo run examples/family.nl "Homer is a parent of Lisa?" --explain

The CLI uses PyJevUnifier by default for run; pass --exact-only to force deterministic offline execution. Semantic confidence and backend checks are diagnostic signals, not theorem probabilities.

Documentation

Read the full documentation for:

The documentation also covers strict safety validation, quoted atoms, recursion, search limits, traces, debugging, development, and the generated API reference.

Development

For a source checkout, install contributor and documentation dependencies:

python -m pip install -e '.[dev,docs]'

Run the quality checks:

python -m compileall inferlingo examples docs
pytest
ruff check .
python docs/make.py html
python -m build
twine check dist/*

The test suite is offline. Semantic tests use fake or injected clients and do not require a live API key.

License

Apache-2.0

Release files for inferlingo 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for inferlingo 0.1.0
File Size Uploaded
inferlingo-0.1.0.tar.gz 61.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for inferlingo 0.1.0
File Interpreter ABI Platform
inferlingo-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 94.7 kB

Release files / inferlingo-0.1.0.tar.gz

Download URL inferlingo-0.1.0.tar.gz
Size 61.6 kB
Tags Source
SHA-256 checksum
How to use checksums
20e2bd85b4e8222cd692c83789205e8a2ea5321cf3b1985736645c15b6f5774d
BLAKE2b-256 checksum
How to use checksums
03068b9b9857113a0d6dd49be3219d1159c09ef3e250123b50fb8c4977e2ffad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / inferlingo-0.1.0-py3-none-any.whl

Download URL inferlingo-0.1.0-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e5661abbfa1614928336ce3577672d504bcc8a3eb7d164b15b8ca195de3c50e
BLAKE2b-256 checksum
How to use checksums
55e1db1efa8850e65f601938e67f03e596bee71631f4095fd17813953b01f6c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page