Skip to main content

Python Distributed Hash Table

Build Status Docs Status Coverage Status

Documentation can be found at kademlia.readthedocs.org.

This library is an asynchronous Python implementation of the Kademlia distributed hash table. It uses the asyncio library in Python 3 to provide asynchronous communication. The nodes communicate using RPC over UDP to communiate, meaning that it is capable of working behind a NAT.

This library is a fork of the kademlia Python library. It is intended to be roughly equivalent, but due to this library having security fixes, it is not compatible with the original nor other reference kademlia implementations. Specifically the use of sha1 and pickle have been replaced by better choices

Installation

pip install secure-kademlia

Usage

This assumes you have a working familiarity with asyncio.

Assuming you want to connect to an existing network:

import asyncio
from kademlia.network import Server

async def run():
    # Create a node and start listening on port 5678
    node = Server()
    await node.listen(5678)

    # Bootstrap the node by connecting to other known nodes, in this case
    # replace 123.123.123.123 with the IP of another node and optionally
    # give as many ip/port combos as you can for other nodes.
    await node.bootstrap([("123.123.123.123", 5678)])

    # set a value for the key "my-key" on the network
    await node.set("my-key", "my awesome value")

    # get the value associated with "my-key" from the network
    result = await node.get("my-key")
    print(result)

asyncio.run(run())

Initializing a Network

If you're starting a new network from scratch, just omit the node.bootstrap call in the example above. Then, bootstrap other nodes by connecting to the first node you started.

See the examples folder for a first node example that other nodes can bootstrap connect to and some code that gets and sets a key/value.

Logging

This library uses the standard Python logging library. To see debut output printed to STDOUT, for instance, use:

import logging

log = logging.getLogger('kademlia')
log.setLevel(logging.DEBUG)
log.addHandler(logging.StreamHandler())

Running Tests

To run tests:

pip install -r dev-requirements.txt
pytest

Reporting Issues

Please report all issues on github.

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).

Metadata

Release files for secure-kademlia 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for secure-kademlia 0.0.0
File Size Uploaded
secure-kademlia-0.0.0.tar.gz 16.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for secure-kademlia 0.0.0
File Interpreter ABI Platform
secure_kademlia-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.8 kB

Release files / secure-kademlia-0.0.0.tar.gz

Download URL secure-kademlia-0.0.0.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e4b8be32e3b48e8fff730b09af0b946ab6a4202d89635b6e33a92566b4b08747
BLAKE2b-256 checksum
How to use checksums
f0c9c7f14320a9fd9a490b29bcc3c18d83858b3b083f2efb9455cc3a33ae58d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / secure_kademlia-0.0.0-py3-none-any.whl

Download URL secure_kademlia-0.0.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cd4bf3926fddac0452b2f2ae711763c86770f0cdb8a02b14fcd93edd015926f
BLAKE2b-256 checksum
How to use checksums
2ccd6204b5f497c83000e1d41a4ec64444d34b953c659d75a6b66356efb8d37a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page