Kademlia is a distributed hash table for decentralized peer-to-peer computer networks.
Project description
# Python Distributed Hash Table
[](https://travis-ci.org/bmuller/kademlia)
[](http://kademlia.readthedocs.org)
**Documentation can be found at [kademlia.readthedocs.org](http://kademlia.readthedocs.org/).**
This library is an asynchronous Python implementation of the [Kademlia distributed hash table](http://en.wikipedia.org/wiki/Kademlia). It uses the [asyncio library](https://docs.python.org/3/library/asyncio.html) in Python 3 to provide asynchronous communication. The nodes communicate using [RPC over UDP](https://github.com/bmuller/rpcudp) to communiate, meaning that it is capable of working behind a [NAT](http://en.wikipedia.org/wiki/Network_address_translation).
This library aims to be as close to a reference implementation of the [Kademlia paper](http://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf) as possible.
## Installation
```
pip install kademlia
```
## Usage
*This assumes you have a working familiarity with [asyncio](https://docs.python.org/3/library/asyncio.html).*
Assuming you want to connect to an existing network:
```python
import asyncio
from kademlia.network import Server
loop = asyncio.get_event_loop()
# Create a node and start listening on port 5678
node = Server()
loop.run_until_complete(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.
loop.run_until_complete(node.bootstrap([("123.123.123.123", 5678)]))
# set a value for the key "my-key" on the network
loop.run_until_complete(node.set("my-key", "my awesome value"))
# get the value associated with "my-key" from the network
result = loop.run_until_complete(node.get("my-key"))
print(result)
```
## 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](https://docs.python.org/3/library/logging.html). To see debut output printed to STDOUT, for instance, use:
```python
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
python -m unittest
```
## Reporting Issues
Please report all issues [on github](https://github.com/bmuller/kademlia/issues).
## 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).
[](https://travis-ci.org/bmuller/kademlia)
[](http://kademlia.readthedocs.org)
**Documentation can be found at [kademlia.readthedocs.org](http://kademlia.readthedocs.org/).**
This library is an asynchronous Python implementation of the [Kademlia distributed hash table](http://en.wikipedia.org/wiki/Kademlia). It uses the [asyncio library](https://docs.python.org/3/library/asyncio.html) in Python 3 to provide asynchronous communication. The nodes communicate using [RPC over UDP](https://github.com/bmuller/rpcudp) to communiate, meaning that it is capable of working behind a [NAT](http://en.wikipedia.org/wiki/Network_address_translation).
This library aims to be as close to a reference implementation of the [Kademlia paper](http://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf) as possible.
## Installation
```
pip install kademlia
```
## Usage
*This assumes you have a working familiarity with [asyncio](https://docs.python.org/3/library/asyncio.html).*
Assuming you want to connect to an existing network:
```python
import asyncio
from kademlia.network import Server
loop = asyncio.get_event_loop()
# Create a node and start listening on port 5678
node = Server()
loop.run_until_complete(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.
loop.run_until_complete(node.bootstrap([("123.123.123.123", 5678)]))
# set a value for the key "my-key" on the network
loop.run_until_complete(node.set("my-key", "my awesome value"))
# get the value associated with "my-key" from the network
result = loop.run_until_complete(node.get("my-key"))
print(result)
```
## 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](https://docs.python.org/3/library/logging.html). To see debut output printed to STDOUT, for instance, use:
```python
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
python -m unittest
```
## Reporting Issues
Please report all issues [on github](https://github.com/bmuller/kademlia/issues).
## 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
kademlia-2.1.tar.gz
(15.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
kademlia-2.1-py3-none-any.whl
(20.0 kB
view details)
File details
Details for the file kademlia-2.1.tar.gz.
File metadata
- Download URL: kademlia-2.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52efd1dd647d7088ab8c49f3c0d4c67da611265ddc8b756a8f8a81ad81f9e7c3
|
|
| MD5 |
c93393381e51bff1e578d13a2b6a6c9d
|
|
| BLAKE2b-256 |
f3736dc97d034df10aa2a5a2f5875972ccf4c00ec40b76f7dc207c02c5d8d3ed
|
File details
Details for the file kademlia-2.1-py3-none-any.whl.
File metadata
- Download URL: kademlia-2.1-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76335f0e91c14a5a166ee4e15d40ffdeec97d7993268e4b31809bf0556974ee2
|
|
| MD5 |
41534baca4948f460ba9610b8623c998
|
|
| BLAKE2b-256 |
28de7703c62b3056b59ef300e57d3272cfd255d2fb8a73d83662e5dd76112a5c
|