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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…