{"id":5400,"library":"pylog","title":"Pylog - Pythonic Prolog Features","description":"Pylog is a lightweight Python library that implements core features of Prolog, enabling logic programming paradigms within Python. It allows defining facts and rules to perform simple logical deductions and goal-oriented queries. The current stable version is 1.1, with an infrequent release cadence focusing on stability and minor enhancements.","status":"active","version":"1.1","language":"en","source_language":"en","source_url":"https://github.com/RussAbbott/pylog","tags":["prolog","logic-programming","ai","declarative-programming"],"install":[{"cmd":"pip install pylog","lang":"bash","label":"Install Pylog"}],"dependencies":[],"imports":[{"note":"The project structure was reorganized, requiring imports from the `pylog.pylog` submodule rather than the top-level package.","wrong":"import pylog","symbol":"facts, rules, goal, run","correct":"from pylog.pylog import facts, rules, goal, run"}],"quickstart":{"code":"from pylog.pylog import facts, rules, goal, run\n\n# Define facts\nfacts(\"human(socrates)\")\nfacts(\"human(plato)\")\n\n# Define a rule: All humans are mortal\n# The body is a list of predicates that must be true for the head to be true.\nrules(\"mortal(X)\", [\"human(X)\"])\n\n# Define a goal to find all mortal beings\ngoal(\"mortal(X)\")\n\n# Run the inference engine to find solutions\nsolutions = run()\n\nprint(\"Solutions for mortal(X):\")\nfor s in solutions:\n    print(s)\n\n# Example for a specific query\ngoal(\"mortal(socrates)\")\nsolutions_socrates = run()\nprint(\"\\nSolutions for mortal(socrates):\")\nfor s in solutions_socrates:\n    print(s)","lang":"python","description":"This quickstart demonstrates how to define facts, create a simple rule using other predicates, set a goal, and retrieve solutions using the `run()` function. It showcases basic logical inference capabilities."},"warnings":[{"fix":"Update all import statements. Instead of `import pylog` or `from pylog import symbol`, use `from pylog.pylog import symbol` for functions like `facts`, `rules`, `goal`, and `run`.","message":"The project underwent significant restructuring around versions `1.0`/`1.1` (including the 'test1' release), which changed the import paths for core functions.","severity":"breaking","affected_versions":"<1.0"},{"fix":"Be aware that the knowledge base is global. For applications requiring isolated logical contexts, manually manage state or consider external mechanisms, as `pylog` does not provide explicit APIs for context management or resetting the knowledge base directly.","message":"Pylog heavily relies on global state for its `facts` and `rules` knowledge base. Calls to `facts()` and `rules()` modify a shared global state.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the library's GitHub repository for current capabilities and examples. Do not expect full Prolog compatibility; plan your logic programming tasks accordingly within the library's demonstrated scope.","message":"Pylog implements a subset of Prolog's features. It may not support advanced Prolog constructs like complex data structures, explicit cut/fail predicates, or certain types of recursion with optimal performance.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}