wiki:Notes/PythonXMPP

XMPP and Python

Don't seem to be any solid, reliable, full-featured Python XMPP servers.

Even the clients don't seem all that solid, except for SleekXMPP.

See PythonAgents#Spade

Google Cloud

https://cloud.google.com/appengine/docs/python/xmpp/ - Google Cloud

https://www.google.com/#q=python+messaging

See GoogleCloud

Clients

SleekXMPP

From examples on pypi

Projects using SleekXMPP tend to follow a basic pattern for setting up client/component connections and configuration. Here is the gist of the boilerplate needed for a SleekXMPP based project. See the documetation or examples directory for more detailed archetypes for SleekXMPP projects.

    import logging

    from sleekxmpp import ClientXMPP
    from sleekxmpp.exceptions import IqError, IqTimeout


    class EchoBot(ClientXMPP):

        def __init__(self, jid, password):
            ClientXMPP.__init__(self, jid, password)

            self.add_event_handler("session_start", self.session_start)
            self.add_event_handler("message", self.message)

            # If you wanted more functionality, here's how to register plugins:
            # self.register_plugin('xep_0030') # Service Discovery
            # self.register_plugin('xep_0199') # XMPP Ping

            # Here's how to access plugins once you've registered them:
            # self['xep_0030'].add_feature('echo_demo')

            # If you are working with an OpenFire server, you will
            # need to use a different SSL version:
            # import ssl
            # self.ssl_version = ssl.PROTOCOL_SSLv3

        def session_start(self, event):
            self.send_presence()
            self.get_roster()

            # Most get_*/set_* methods from plugins use Iq stanzas, which
            # can generate IqError and IqTimeout exceptions
            #
            # try:
            #     self.get_roster()
            # except IqError as err:
            #     logging.error('There was an error getting the roster')
            #     logging.error(err.iq['error']['condition'])
            #     self.disconnect()
            # except IqTimeout:
            #     logging.error('Server is taking too long to respond')
            #     self.disconnect()

        def message(self, msg):
            if msg['type'] in ('chat', 'normal'):
                msg.reply("Thanks for sending\n%(body)s" % msg).send()


    if __name__ == '__main__':
        # Ideally use optparse or argparse to get JID,
        # password, and log level.

        logging.basicConfig(level=logging.DEBUG,
                            format='%(levelname)-8s %(message)s')

        xmpp = EchoBot('somejid@example.com', 'use_getpass')
        xmpp.connect()
        xmpp.process(block=True)

Python Qpid

https://qpid.apache.org/releases/qpid-0.20/messaging-api/python/examples/index.html - Python and Qpid

Code segment from https://qpid.apache.org/releases/qpid-0.20/messaging-api/python/examples/drain.html:

...
def __getitem__(self, st):
    return eval(st, self.environ)
...

Hoo boy ...

See JavaServers#Qpid

See

GoogleAppEngine#XMPP

PythonOpenfire

Messaging#XMPP

PythonAgents#Spade

PythonServers#XMPP

PythonTwistdServer#TwistdXMPPRouter

Also See

Search wiki for 'xmpp'

https://code.activestate.com/pypm/search:xmpp/

Last modified 2 years ago Last modified on 04/23/2015 04:17:31 AM