jabberbot: A simple framework for creating Jabber/XMPP bots and services in Python

Translations of this page: Serbo-Croatian (by Anja Skrba)

Programming your own Jabber bot can be fun and helpful. This is python-jabberbot, a Jabber bot framework for Python that enables you to easily write simple Jabber bots. You can use your Jabber bots to provide information about your running systems, to make your website interact with your visitors or notify you about updates or changes you monitor with your Python scripts.

[...] now I have the 'bot bug' and I want to write bots for all kinds of things, since it's so easy to do. Thanks again!

This Jabber bot is partly inspired by the xmpppy example bot.py, but designed to be re-usable and to make it easy to write small Jabber bots that do one thing and do it well.

License: GNU General Public License, Version 3 or later (GPLv3)

Mailing list

We now have a mailing list for discussing the development of the JabberBot module:

Dependencies

Documentation

Debian Package

Thanks to Carl Chenet, python-jabberbot is now available as a Debian package for easy installation on Debian and derived systems:

Download

Current version: jabberbot-0.15.tar.gz (Released: 2012-03-08)

Development repository (Git)

You can get the latest and greatest code via Git:

git clone git://git.code.sf.net/p/pythonjabberbot/code

Release history

The current ChangeLog can always be found on http://sourceforge.net/p/pythonjabberbot/code/ and the old ChangeLog is still available.

Usage

  1. Import the class: from jabberbot import JabberBot, botcmd
  2. Subclass the JabberBot class
  3. Add methods and decorate them with "@botcmd". The signature of the methods should look like this: def somecommand(self, mess, args) - the methods should return the message sent back to the user as string (or None if the command gives no reply)
  4. Create an instance of your bot, supplying username and password
  5. Call the serve_forever() method of your instance
  6. You can call the send() method on your bot to send messages to specific users

Example code

from jabberbot import JabberBot, botcmd
import datetime

class SystemInfoJabberBot(JabberBot):
@botcmd
def serverinfo( self, mess, args):
"""Displays information about the server"""
version = open('/proc/version').read().strip()
loadavg = open('/proc/loadavg').read().strip()

return '%s\n\n%s' % ( version, loadavg, )

@botcmd
def time( self, mess, args):
"""Displays current server time"""
return str(datetime.datetime.now())

@botcmd
def rot13( self, mess, args):
"""Returns passed arguments rot13'ed"""
return args.encode('rot13')

@botcmd
def whoami(self, mess, args):
"""Tells you your username"""
return mess.getFrom().getStripped()

username = 'my-jabberid@jabberserver.example.org'
password = 'my-password'
bot = SystemInfoJabberBot(username,password)
bot.serve_forever()

More examples

Starting with version 0.7, more examples can be found in the examples/ subdirectory of the source distribution.

Screenshot

Related projects

Yoan Blanc has done a similiar project using Python and the Twisted framework: A IM bot as an user interface (kind of).

Projects using python-jabberbot

Thomas Perl · 2013-04-14