Did you know ... Search Documentation:
News

Janus provides a bi-directional interface to Python

0 upvotes 0 0 downvotes
Picture of user Jan Wielemaker.

The new Janus package allows embedding Python into SWI-Prolog as well as SWI-Prolog into Python. It provides a bi-directional interface with a high level mapping between the dynamically typed data of both systems. Prolog calls Python using py_call/2 or py_iter/2 to backtrack over a Python iterator or generator. Python can use janus.once() to cal a predicate as once/1 while janus.Query() implements a Python iterator from a non-deterministic Prolog predicate.

Janus comes as a Prolog library (embedding Python in Prolog) and a Python package for embedding Prolog in Python. After loading either way, the interface fully equivalent.

The library provides excellent performance, transferring a list of 1M integers in less than 0.1 second, allow Prolog to call Python functions and methods at about 1M calls per second and Python calling Prolog at about 0.5M calls per second.

Janus was created by Theresa Swift and Carl Anderson for XSB. The two implementations are independent. We are close to agreeing on a common subset that will work on both implementations such that we can develop libraries that exploit Python that are portable across systems that provide Janus.