Skip to main content

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

pykqml-1.2.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

pykqml-1.2-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file pykqml-1.2.tar.gz.

File metadata

  • Download URL: pykqml-1.2.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.0

File hashes

Hashes for pykqml-1.2.tar.gz
Algorithm Hash digest
SHA256 1e80e36d80b51f5e7dfe7baa4cce8c7d98dbf9a91d3595a02e4ca7b28d95c4e5
MD5 670f7b6f4a4133d567224a632f1e4e10
BLAKE2b-256 82845b500c127cac76a5729851e7bdc24335a1ba199eeb560f688baabf18a602

See more details on using hashes here.

File details

Details for the file pykqml-1.2-py3-none-any.whl.

File metadata

  • Download URL: pykqml-1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.0

File hashes

Hashes for pykqml-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0779f9bdf73e8e21291cbd66eab3d15ce62796c8b40cc54b8ea8ffff9850db5
MD5 2a203926411924616942352bbb23f9de
BLAKE2b-256 fac764a4751e2f3520c5ce29ddd0965aff7e761f427a3e143d379ec30a1d5a9c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page