Relational/Logic Programming in Python?

19,182

Solution 1

Perhaps you should google "Logic Programming in Python". Pyke looks promising:

Pyke introduces a form of Logic Programming (inspired by Prolog) to the Python community by providing a knowledge-based inference engine (expert system) written in 100% Python.

Unlike Prolog, Pyke integrates with Python allowing you to invoke Pyke from Python and intermingle Python statements and expressions within your expert system rules.

Solution 2

You may want to use pyDatalog, a logic programming library that I developed for Python implementing Datalog. It also works with SQLAlchemy to query relational databases using logic clauses.

Solution 3

As we are heading toward 2019, I recommend PySWIP over others recommended here. It is actively maintained and has an easy interface, unlike Pyke (9 years ago) or PyLog (6 years ago).

Solution 4

LogPy is an implementation of miniKanren, a relational programming language, in Python. It follows in th tradition of core.logic, the preeminent logic programming solution in Clojure. LogPy was designed for interoperability with pre-existing codebases.

Solution 5

Another option is Yield Prolog

Share:
19,182
AJ.
Author by

AJ.

Making a difference one API at a time.

Updated on June 27, 2022

Comments

  • AJ.
    AJ. almost 2 years

    I'm a longtime python developer and recently have been introduced to Prolog. I love the concept of using relationship rules for certain kinds of tasks, and would like to add this to my repertoire.

    Are there any good libraries for logic programming in Python? I've done some searching on Google but only found the following:

    jtauber's blog series on relational_python

    Would love to compare to some others...thanks!

    -aj

  • AJ.
    AJ. over 14 years
    @Richie, looks like a useful package. Thanks for the pointer!
  • heltonbiker
    heltonbiker about 13 years
    from Pyke's page: "Pyke introduces a form of Logic Programming (inspired by Prolog) to the Python community by providing a knowledge-based inference engine (expert system) written in 100% Python."
  • andrew cooke
    andrew cooke almost 13 years
    is Dee an implementation of D (as described in Date's books?)
  • greg
    greg almost 13 years
    It is (without the object/type specifications)
  • Janus Troelsen
    Janus Troelsen over 12 years
    too bad it seems dead. looked promising
  • andrew cooke
    andrew cooke about 12 years
    that's very cool, but does it inter-operate with python? it is written on top of pypy, which also supports (famously) a python implementation, but it's not clear to me that implies inter-op. also, while i am here, blog.herraiz.org/archives/238 is a few years old, but listed various options (it implies pyrolog inter-op, but also sounds like it is simply assumed because of pypy, which is what i am questioning).
  • false
    false about 12 years
    Proof-of-concept rather. So going with the soruces might permit that.
  • ThiefMaster
    ThiefMaster over 11 years
    You need to disclose that it's your project!
  • user48956
    user48956 over 4 years
    Is it straightfoward to apply tabling in PySWIP (to avoid infinite loops, etc...?), as in pyDatalog.