Skip to main content

2PPy: tuProlog for Python

PyPI Python CI/CD Docs License

2PPy brings tuProlog (2P-Kt) to Python: logic terms, unification, theories, Prolog and ProbLog solvers, predicates written in Python, and Prolog code driving Python objects, through a Pythonic API over 2P-Kt (via JPype).

Documentation: https://tuprolog.github.io/2ppy/

Installation

pip install 2ppy        # or: uv add 2ppy

Python 3.10 or later. The package bundles 2P-Kt and a Java runtime: no Java installation is needed.

Quick start

>>> from tuprolog.solve.prolog import prolog_solver
>>> from tuprolog.theory.parsing import parse_theory
>>> solver = prolog_solver(
...     static_kb=parse_theory("""
...     parent(abe, homer). parent(homer, bart). parent(homer, lisa).
...     ancestor(X, Y) :- parent(X, Y).
...     ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
... """)
... )
>>> list(solver.query("ancestor(abe, D)"))
[{'D': 'homer'}, {'D': 'bart'}, {'D': 'lisa'}]

Predicates can be written in Python:

>>> from tuprolog.solve.library import library
>>> from tuprolog.solve.primitive import predicate
>>> lib = library("my.lib", primitives={"upper/2": predicate(lambda s, _: [(s, s.upper())])})
>>> list(prolog_solver(libraries=lib).query("upper(hello, U)"))
[{'U': 'HELLO'}]

Interactive Prolog: python -m tuprolog.repl.prolog, or the terminal IDE: 2ppy-tui (also as a Docker image: docker run -it --rm ghcr.io/tuprolog/2ppy).

See the tutorials and the example notebooks to get started, and the API reference for the details.

Contributing

uv sync && uv run poe build-jars    # environment and JARs (requires a JDK 17+)
uv run poe static-checks            # what CI checks
uv run poe test                     # tests, including every documented example
uv run poe docs                     # the documentation site

See Contribute and AGENTS.md. Releases are automated by semantic-release from Conventional Commits.

Metadata

Release files for 2ppy 1.7.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 2ppy 1.7.0
File Size Uploaded Provenance
2ppy-1.7.0.tar.gz 15.3 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 30.6 MB

Release files / 2ppy-1.7.0.tar.gz

Download URL 2ppy-1.7.0.tar.gz
Size 15.3 MB
Tags Source
SHA-256 checksum
How to use checksums
46abd2a0b836b35067334d438a231f0a2281bc0aadb8dd72eb969e21e6e115b1
BLAKE2b-256 checksum
How to use checksums
28b56e376b21fd29616e4803547f236888d98aba8431ff9791cf68de3fc15e44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / 2ppy-1.7.0-py3-none-any.whl

Download URL 2ppy-1.7.0-py3-none-any.whl
Size 15.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
39d81de362de4660b29e76865ef02325403a851425a433f57c86cfb1c11c4dab
BLAKE2b-256 checksum
How to use checksums
54eea31dd842551de5b71ee199ed99af93e14dd058da3d1e64871c27d9124a0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for 2ppy 1.7.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files No provenance

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