Kademlia is a distributed hash table for decentralized peer-to-peer computer networks.
Project description
Python Distributed Hash Table
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 aims to be as close to a reference implementation of the Kademlia paper as possible.
Installation
pip install 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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file kademlia-2.2.2.tar.gz
.
File metadata
- Download URL: kademlia-2.2.2.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22928c2e92544c7223ed5905c42bfea291336851beec7de436af4ca41ac0d8eb |
|
MD5 | 684d97f19a47f8625512678663bf6177 |
|
BLAKE2b-256 | 5e855e54903d20e3ff7aa7a6a1d7be289b254a67a18cc7f94b7cdfeacf10af69 |
File details
Details for the file kademlia-2.2.2-py3-none-any.whl
.
File metadata
- Download URL: kademlia-2.2.2-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47696d2e75d60d71eda47fe2e21a96312b0a05f850f9a6910073b5cd79494d0e |
|
MD5 | ea64f30037d5f30a46a1fcc8f4f47363 |
|
BLAKE2b-256 | 111d8d151cc631bd6e1590aab5e5f5c4643ebe43db51dc70121ea0819af94077 |