Skip to main content

2PPy (tuProlog in Python)

Experimental porting of 2P-Kt on Python, via JPype.

This is a work in progress.

Introduction

Object-oriented and modular ecosystem for symbolic AI and logic programming, currently featuring:

  • a command-line interface, in the form of a REPL

  • a module for logic terms and clauses representation, namely tuprolog.core

  • a module for logic unification, namely tuprolog.unify

  • a module for in-memory indexing and storing logic theories, namely tuprolog.theory

  • a module for other indexed collections of logic clauses (multi-sets and queues), namely tuprolog.collections

  • a module providing generic API for resolution of logic queries, namely tuprolog.solve

    • a module that implements deterministic logic programming and solving, namely tuprolog.solve.prolog
    • a module that implements probabilistic logic programming and solving, namely tuprolog.solve.problog
    • a module exposing 2P-Kt's IO library (e.g. read/1, get_char/1, open/3), namely tuprolog.solve.libs
  • two parsing modules: one aimed at parsing terms, namely tuprolog.core.parsing, and the other aimed at parsing theories, namely tuprolog.theory.parsing

How to use 2ppy

Installing 2ppy

Install 2PPy from PyPI (Python 3.10 or later):

pip install 2ppy        # or: uv add 2ppy

The package ships 2P-Kt's JARs, and depends on jdk4py, which bundles a Java runtime: no separate Java installation is required. The JVM is started when tuprolog is first imported.

Use 2ppy as a Python library

  1. Import tuprolog.* modules in your Python scripts
  2. Use the Pythonic API to write, parse or solve your logic programs. You can find some examples in the tests folder.
  3. Python values are converted where terms are expected (e.g. struct("f", "a", 1) is f(a, 1), see tuprolog.core.to_term). Methods without a Pythonic counterpart are forwarded to the underlying JVM objects, so they may return JVM types (e.g. java.lang.String).
  4. Python streams (io.IOBase, e.g. files, sys.stdin, io.StringIO, io.BytesIO) are accepted wherever 2P-Kt reads or writes: parsers (read_theory(open("kb.pl"))), solvers' channels (prolog_solver(std_in=io.StringIO("..."), std_out=buffer)), and JVM methods expecting streams (binary), readers or writers (text). Binary streams are UTF-8 encoded. By default, solvers read from and write on Python's current sys.stdin, sys.stdout and sys.stderr.

Use 2PPy as an interactive REPL

  1. Python shell mode: run python -m tuprolog
  2. Logic solver REPL:
    1. run python -m tuprolog.repl.prolog for Prolog
    2. run python -m tuprolog.repl.problog for ProbLog

How to contribute to 2PPy

The project follows template-python-project-uv. Requirements: uv and Apache Maven (mvn on the PATH), which downloads 2P-Kt's JARs from Maven Central, as declared in pom.xml.

uv sync                      # create the environment, with the development tools
uv run poe fetch-jars        # download the JARs into tuprolog/libs/ (needed before testing or building)
uv run poe test              # run the tests
uv run poe static-checks     # compileall, ruff format --check, ruff check, mypy (what CI runs)
uv run poe static-fixes      # ruff check --fix + ruff format
uv run poe coverage && uv run poe coverage-report
uv build                     # wheel and sdist in dist/ (JARs included)

Write the code inside tuprolog/ and the tests inside tests/. Contributor notes (layout, conventions) are in AGENTS.md. Optional local Git hooks: uv run poe install-hooks [HOOK...] (pre-commit, conventional-commits, no-ai-signature, pre-push).

Releases

Commits follow Conventional Commits: on every push to master, semantic-release derives the next version from them, publishes it on PyPI, and creates the corresponding GitHub Release. pyproject.toml is the only version source: never bump it by hand. The release workflow needs the PYPI_TOKEN and RELEASE_TOKEN repository secrets.

CI runs the static checks and the tests on Ubuntu, Windows and macOS, with Python 3.10 to 3.13. Dependencies are kept up to date by Renovate.

Metadata

Release files for 2ppy 1.2.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.2.0
File Size Uploaded Provenance
2ppy-1.2.0.tar.gz 12.2 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 24.5 MB

Release files / 2ppy-1.2.0.tar.gz

Download URL 2ppy-1.2.0.tar.gz
Size 12.2 MB
Tags Source
SHA-256 checksum
How to use checksums
1c2a147df0cc4ab93e5695cf8848704a96017691e9b34b1af0708105aa2e0e98
BLAKE2b-256 checksum
How to use checksums
cc91ef107a27c8e78a84729a4d94314a0614c4a06b444d5d738f0d6757bb9060
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.2.0-py3-none-any.whl

Download URL 2ppy-1.2.0-py3-none-any.whl
Size 12.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b3b38ce03a79a82c8ebcef7ce18583db23cbdc30253131a4624285129e53ab09
BLAKE2b-256 checksum
How to use checksums
fe0c20fb4e6ec9d6520d34e27322bb24df2542520770f6a66af93c0d43b26137
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.2.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.2.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