Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
See the Change Log.
If you have SWI-Prolog installed, it's just:
pip install -U pyswip
See Get Started for detailed instructions.
PySwip is a Python-Prolog interface that enables querying SWI-Prolog in your Python programs. It features an SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.
Since PySwip uses SWI-Prolog as a shared library and ctypes to access it, it doesn't require compilation to be installed.
PySwip was brought to you by the PySwip community. Thanks to all contributors.
from pyswip import Prolog
Prolog.assertz("father(michael,john)")
Prolog.assertz("father(michael,gina)")
list(Prolog.query("father(michael,X)")) == [{'X': 'john'}, {'X': 'gina'}]
for soln in Prolog.query("father(X,Y)"):
print(soln["X"], "is the father of", soln["Y"])
# michael is the father of john
# michael is the father of gina
An existing knowledge base stored in a Prolog file can also be consulted, and queried. Assuming the filename "knowledge_base.pl" and the Python is being run in the same working directory, it is consulted like so:
from pyswip import Prolog
Prolog.consult("knowledge_base.pl")
from pyswip import Prolog, registerForeign
def hello(t):
print("Hello,", t)
hello.arity = 1
registerForeign(hello)
Prolog.assertz("father(michael,john)")
Prolog.assertz("father(michael,gina)")
print(list(Prolog.query("father(michael,X), hello(X)")))
from pyswip import Functor, Variable, Query, call
assertz = Functor("assertz", 1)
father = Functor("father", 2)
call(assertz(father("michael","john")))
call(assertz(father("michael","gina")))
X = Variable()
q = Query(father("michael",X))
while q.nextSolution():
print("Hello,", X.value)
q.closeQuery()
# Outputs:
# Hello, john
# Hello, gina
The core functionality of Prolog.query
is based on Nathan Denny's public domain prolog.py.
PySwip was used in scientific articles, dissertations, and student projects over the years. Head out to PySwip Community for more information and community links.
Do you have a project, video or publication that uses/mentions PySwip? file an issue or send a pull request.
If you would like to reference PySwip in a LaTeX document, you can use the provided BibTeX file. You can also use the following information to refer to PySwip:
PySwip is licensed under the MIT license.
FAQs
PySwip enables querying SWI-Prolog in your Python programs.
We found that pyswip demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.