Skip to main content

An OTR-XMPP communications channel

Project description

This is a Python library for communicating with XMPP destinations using OTR (Off-the-Record Messaging) encryption.


  • Your internet application can talk securely to you on your PC or smartphone using readily-available chat software with OTR support
  • OTRv2
  • Send to and receive from multiple destinations, with or without fingerprint verification
  • Pure python (no libotr dependency)


$ sudo pip install --pre xmpppy  # xmpppy is tagged as an "rc" version
$ sudo pip install otrxmppchannel


import time
from otrxmppchannel import OTRXMPPChannel
from otrxmppchannel.connection import OTR_TRUSTED, OTR_UNTRUSTED,

# Load the base64-encoded OTR DSA key. Constructing the object without
# a key will generate one and provide it via ValueError exception.
privkey = open('.otrprivkey', 'r').read()

class MyOTRChannel(OTRXMPPChannel):
    def on_receive(self, message, from_jid, otr_state):
        if otr_state == OTR_TRUSTED:
            state = 'trusted'
        elif otr_state == OTR_UNTRUSTED:
            state = 'UNTRUSTED!'
        elif otr_state == OTR_UNENCRYPTED:
            state = 'UNENCRYPTED!'
            state = 'UNKNOWN OTR STATUS!'
        print('received %s from %s (%s)' % (message, from_jid, state))

mychan = MyOTRXMPPChannel(

mychan.send('')  # Force OTR setup
time.sleep(3)  # Wait a bit for OTR setup to complete
mychan.send('This message should be encrypted')


  • XMPP invitations are not handled
  • It seems to take roughly 3 seconds to set up an OTR session. Messages sent before the session is ready may be lost.
  • The private key serialization format is specific to pure-python-otr. Conversions from other formats are not handled.



If you found this software useful and would like to encourage its maintenance and further development, please consider making a donation to the Bitcoin address 1MWFhwdFVEhB3X4eVsm9WxwvAhaxQqNbJh.


This is free and unencumbered public domain software. For more information, see or the accompanying UNLICENSE file.

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
OTRXMPPChannel-1.0.4.tar.gz (6.2 kB) Copy SHA256 hash SHA256 Source None Mar 25, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page