Skip to main content

Implements consistent hashing with Python and the algorithm is the same as libketama.

Project description


Implements consistent hashing that can be used when the number of server nodes can increase or decrease.The algorithm that is used for consistent hashing is the same as libketama <>


It’s so easy to use^_^:

from consistent_hash import ConsistentHash

# You can construct consistent hash with the below three ways
con_hash = ConsistentHash({'':1, '':2, '':1})
# Or
con_hash = ConsistentHash(['', '', '']))
# Or
con_hash = ConsistentHash('')

# Add servers to hash ring
# Get a server via the key of object
server = con_hash.get_node('my_key')
# Delete the server from hash ring, you don't need to indicate weights
con_hash.del_nodes(['', ''])

Unit test

  • Firstly, install nose which extends unittest to make testing easier:

    pip install nose
  • Then, run tests:

    # Option -s any stdout output will be printed immediately
    # and -v be more verbose
    nosetests -s -v

More information about nose <>

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Files for consistent_hash, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size consistent_hash-1.0-py2.7.egg (6.8 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size consistent_hash-1.0.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page