The directory src/python_api
contains a definition for a Pedro client class in the file pedroclient.py
. This directory also contains a program pedro_gui.py
that uses this API and provides an interface to subscriptions and notifications.
Below is a simple example using this class withing the python interpreter.
>>> from pedroclient import * >>> me = PedroClient() >>> me.subscribe('f(X)') 1 >>> me.notify('f(a)') 1 >>> me.get_notification() ('f(a)', 0) >>> me.notify('f(g(12, "hi"))') 1 >>> print me.get_term()[0] f(g(12, "hi")) >>>
PedroClient(machine='localhost', port=4550, async = True)
hostname
using the port port
. If async
is true a thread is created to process Pedro messages. If not, a call to notification_ready
will process any Pedro messages. If the main program has its own event loop (e.g. in pygame) then the program runs faster setting async
to False
and adding notification_ready
to the loop.disconnect()
connect()
notify(term)
term
as a notification to the Pedro server.subscribe(term, goal = 'true', rock = 0)
unsubscribe(ID)
register(name)
deregister()
p2p(toaddr, term)
term
to the address toaddr
using the peer-to-peer support. The machine part of the address can be elided if it is to a process on the same machine. Do not use localhost
as the name of the machine.get_notification()
async == True
and returns None
if async == false
.get_term()
get_notification
except that the notification is parsed into a Prolog term.parse_string(string)
string
into a Prolog term.notification_ready()
PedroParser()
parse(string)
, parses string
to a Prolog term. If a parse error occurs, a ParserError
exception is thrown that contains the position of the error.