This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Help us improve Python packaging - Donate today!
Project Description
Copyright (c) 2015, Davide Gessa
Copyright (c) 2012, Isaac Zafuta
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

Description: # kad.py

Python3 implementation of the Kademlia DHT data store.

Useful for distributing a key-value store in a decentralized manner.

To create a new DHT swarm, just call DHT() with the host and port that you will listen on. To join an existing DHT swarm, also provide bootstrap host and port numbers of any existing node. The nodes will discover the rest of the swarm as appropriate during usage.


## Example: A two-node DHT

```python
from kad import DHT

host1, port1 = 'localhost', 3000
dht1 = DHT(host1, port1)
host2, port2 = 'localhost', 3001
dht2 = DHT(host2, port2, seeds=[(host1, port1)])
dht1["my_key"] = [u"My", u"json-serializable", u"Object"]

print (dht2["my_key"]) # blocking get
dht2.get ("my_key", lambda data: print (data)) # threaded get
```


## Example: Persistent storage

We can use a custom storage for local data. Storage parameter must an object with __getitem__ and __setitem__.
In this example we use shelve to create a persistent storage.

```python
from kad import DHT
import shelve

host, port = 'localhost', 3000
dht = DHT(host, port, storage=shelve.open ('sto.dat'))
```


## Example: Custom hash function

By default, kad.py doesn't hash keys. We can provide a custom hash_function.

```python
from kad import DHT

host, port = 'localhost', 3000
dht = DHT(host, port, hash_function=lambda d: d[0:4])
```



## Example: Custom request handler

You can extend the default DHTRequestHandler to intercept any kind of messages.

```python
from kad import *

class CustomRequestHandler (kad.DHTRequestHandler):
def handle_store(self, message):
print (message['value'])
return super (CustomRequestHandler, self).handle_store (message)


d = DHT ('localhost', 3030, requesthandler=CustomRequestHandler)

d['ciao'] = {'hola': 12}
```


## Example: Iterate over DHT keys

You can use the DHT object as iterator for stored keys.

```python
from kad import DHT

d = DHT ('localhost', 3100)

d['ciao'] = 'mondo'
d['hello'] = 'world'

for key in d:
print (key, d[key])
```
Platform: UNKNOWN
Release History

Release History

0.5.6

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
kad.py-0.5.6-py3.4.egg (16.9 kB) Copy SHA256 Checksum SHA256 3.4 Egg Nov 27, 2015
kad.py-0.5.6-py3-none-any.whl (26.5 kB) Copy SHA256 Checksum SHA256 py3 Wheel Nov 27, 2015
kad.py-0.5.6.tar.gz (6.2 kB) Copy SHA256 Checksum SHA256 Source Nov 27, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting