Basic idea behind XmppFlask is being as simlpe as Flask is. So let’s start from a simple application.

# -*- coding: utf-8 -*-

from xmppflask import XmppFlask
app = XmppFlask(__name__)

def ping():
    return u'pong'


Routing is pretty much the same as in Flask http://flask.pocoo.org/docs/quickstart/#routing:

@app.route(u'ping <user> <int:n> times')
def ping(user, n):
    return u'ponged %s %s times' % (user, n)

Rendering Templates

Take a look at http://flask.pocoo.org/docs/quickstart/#rendering-templates

def ping():
    return render_template(u'ping.html')



app.logger.debug('A value for debugging')
app.logger.warning('A warning occurred (%d apples)', 42)
app.logger.error('An error occurred')


You may keep session context for each user that interacts with your app. Just define session interface:

from xmppflask import XmppFlask
from xmppflask.session import MemorySessionInterface
from xmppflask import session

app = XmppFlask(__name__)
app.session_interface = MemorySessionInterface()

def ping():
    if 'seq' not in session:
        session['seq'] = 0
    session['seq'] += 1
    return u"ping seq %d. PONG!" % session['seq']

And more

As in Flask you can do things like this:

def before_request():
    g.db = connect_db()

def teardown_request(exception):


In XmppFlask there’s a thing called XMPPWSGI. Basically it’s a “WSGI for XMPP” (as you already might have guessed). To read about the whole WSGI idea you can go and read PEP 333. In XMPPWSGI, your application should be something like this (could be changed in near time):

def xmppwsgi_app(self, environ, notification_queue):
        [('user1@gmail.com', 'notification 1'),
         ('user2@gmail.com', 'notification 2')])
    return u'response to user'

This code is a simple XMPPWSGI app that responses to user by string “response to user” and also says to XMPPWSGI server to send messages to user1@gmail.com and user2@gmail.com.


Just run nosetests inside environment.