Installation

The easiest (and best) way to install kademlia is through pip:

$ pip install kademlia

Usage

Assuming you want to connect to an existing network (run the Stand-alone Server example below if you don’t have a network):

from twisted.internet import reactor
from twisted.python import log
from kademlia.network import Server
import sys

log.startLogging(sys.stdout)

def done(result):
    print "Key result:", result
    reactor.stop()

def setDone(result, server):
    server.get("a key").addCallback(done)

def bootstrapDone(found, server):
    server.set("a key", "a value").addCallback(setDone, server)

server = Server()
server.listen(8468)
server.bootstrap([("1.2.3.4", 8468)]).addCallback(bootstrapDone, server)

reactor.run()

Check out the examples folder for other examples.

Stand-alone Server

If all you want to do is run a local server, just start the example server:

$ twistd -noy examples/server.tac

Running Tests

To run tests:

$ trial kademlia

Fidelity to Original Paper

The current implementation should be an accurate implementation of all aspects of the paper save one - in Section 2.3 there is the requirement that the original publisher of a key/value republish it every 24 hours. This library does not do this (though you can easily do this manually).