Skip to main content

swiplserver integrates SWI Prolog with Python.

Project description

swiplserver

Note that swiplserver 1.0 changes the names of classes from previous versions in an incompatible way -- the terminology changed from 'language server' to 'machine query interface (MQI)'. You'll need to update your code as you transition. The names should be stable from version 1.0 on, however.

The swiplserver module provides a set of classes to call SWI Prolog from Python. It allows running any query from Python that could be executed from the SWI Prolog console (i.e. the "top level"). Answers to Prolog queries are returned as JSON.

The library uses a SWI Prolog interface called the Machine Query Interface ('MQI') that allows Prolog queries to be executed. It also manages launching and shutting down SWI Prolog automatically, making the process management invisible to the developer. The whole experience should feel just like using any other library.

from swiplserver import PrologMQI, PrologThread

with PrologMQI() as mqi:
    with mqi.create_thread() as prolog_thread:
        result = prolog_thread.query("member(X, [color(blue), color(red)])")
        print(result)

[{'X': {'functor': 'color', 'args': ['blue']}},
 {'X': {'functor': 'color', 'args': ['red']}}]

To install and learn how to use the swiplserver Python library, see the docs.

Supported Configurations

Should work on:

  • SWI Prolog 8.2.2 or greater (may work on older builds, untested)
  • Any Mac, Linux Variants or Windows that are supported by SWI Prolog
  • Python 3.7 or later (may work on older builds, untested)

Has been tested with:

  • Ubuntu 20.04.2 + SWI Prolog 8.3.22 + Python 3.7.8
  • Windows 10 Pro 64 bit + SWI Prolog 8.3.27 + Python 3.7.0
  • Windows 8.1 Pro 64 bit + SWI Prolog 8.2.4 + Python 3.8.1
  • MacOS Catalina/Big Sur + SWI Prolog 8.3.24 + Python 3.7.4

Performance

If you're interested in rough performance overhead of the approach this library takes. On a late 2013 macbook pro the per call overhead of the library for running a Prolog query is about:

  • 170 uSec per call using TCP/IP localhost
  • 145 uSec per call using Unix Domain Sockets

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swiplserver-1.0.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swiplserver-1.0.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file swiplserver-1.0.0.tar.gz.

File metadata

  • Download URL: swiplserver-1.0.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for swiplserver-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e27c4253b09468b51ae7f2ff6fe66b8266dfd7477b9da2666d86eaa5fdd287fa
MD5 47351b78066578deb6f25396205d3a70
BLAKE2b-256 e3d566c866ddc8090267b13c335f66416586e42ec597e1e617ee3d7f7f575f09

See more details on using hashes here.

File details

Details for the file swiplserver-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: swiplserver-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for swiplserver-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47415642fa864c9531908476f180947bd455e946f9a47417f3c7fc77d2ebbee2
MD5 c4fa500d6d634c26cf6ac9184ad1fcc3
BLAKE2b-256 829f9a2f39c8756320d339d28b6a70636689462e8fc48a5d0ff407fe4e91cc34

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page