KQML messaging classes in Python.
Project description
PyKQML
PyKQML is an implementation of KQML messaging in Python.
Installation
PyKQML can be installed as
pip install pykqml
Note that releases of PyKQML up to 0.5 work in Python 2 only, whereas releases above and including 1.0 work in Python 3 only.
To install for Python 2, use:
pip install pykqml==0.5
To install for Python 3 (or force an upgrade to a compatible version), use
pip install "pykqml>0.5"
Usage
PyKQML implements the following KQML classes, which allow constructing and manipulating KQML messages programmatically:
KQMLToken KQMLString KQMLQuotation KQMLList KQMLPerformative KQMLReader KQMLDispatcher KQMLModule
You can import KQML classes as, for instance,
from kqml import KQMLList
You can create a new KQML messaging agent in the context of the TRIPS system as
from kqml import KQMLModule
class MyAgent(KQMLModule):
name = "MyAgent" # This is the name of the agent to register with
def __init__(self, **kwargs):
# Call the parent class' constructor which sends a registration
# message, setting the agent's name to be recognized by the
# Facilitator.
super(MyAgent, self).__init__(name=self.name, **kwargs)
# Subscribe to REQUESTs of interest. The list will change
# depending on the role of the agent
for req in ('what-next', 'commit', 'evaluate'):
self.subscribe_request(req)
# Subscribe to TELLs of interest if needed. This list will change
# depending on the role of the agent
for tell in ('log-speechact', ):
self.subscribe_tell(tell)
# Now signal that the agent is ready to receive messages
self.ready()
# Finally, start the listener for incoming messages
self.start()
def receive_request(self, msg, content):
# First, figure out what kind of request this is
task = content.head().upper()
# Here you typically decide what to do based on the
# type of request.
# Construct reply message's content
reply_content = KQMLList()
# Set whatever needs to be set in the reply content
# Finally, wrap the content in a message and reply
reply_msg = KQMLPerformative('reply')
reply_msg.set('content', reply_content)
self.reply(msg, reply_msg)
Testing
You can run all tests by running nosetests in the top level folder.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pykqml-1.1.tar.gz
.
File metadata
- Download URL: pykqml-1.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3df542f3ee6e43c261a5161d3016d1aef3367f98d5e6031e26591c841bd379d3 |
|
MD5 | 64222abf974fe3f336e9c05c3c064412 |
|
BLAKE2b-256 | c177e17d52182b5208f33d9538217733779bea81b23436d5965f1aba9b0e2481 |
File details
Details for the file pykqml-1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pykqml-1.1-py2.py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.7 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f7c1b241fd36d249c3a7d5ddbe0f2c0e54f1769ae9ff55892e7800ecf69a5c6 |
|
MD5 | b4403481a67ec7f1b6741b374950b605 |
|
BLAKE2b-256 | b2bd6e1788cf8043ef921d6be7fbcc1db4f867fcfb0dcb020e47a02522623d58 |