Metadata-Version: 1.0
Name: kad.py
Version: 0.6.0
Summary: Python3 DHT Implementation
Home-page: https://github.com/dakk/kad.py
Author: Davide Gessa, Isaac Zafuta
Author-email: gessadavide@gmail.com, isaac@zafuta.com
License: 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-Content-Type: UNKNOWN
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 hash the keys with md5 function. We can provide a custom hash_function.
        Note: Keep in mind that hash functions must return int values for this implementation.
        
        ```python
        from kad import DHT
        
        host, port = 'localhost', 3000
        dht = DHT(host, port, hash_function=lambda key: int(hashlib.sha256(key.encode('utf8')).hexdigest(), 16))
        ```
        
        
        
        ## 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
