Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Implements consistent hashing in Python (using md5 as hashing function).

Project Description

About hash_ring

Implements consistent hashing that can be used when the number of server nodes can increase or decrease (like in memcached). The hashing ring is built using the same algorithm as libketama.

Consistent hashing is a scheme that provides a hash table functionality in a way that the adding or removing of one slot does not significantly change the mapping of keys to slots.

More about hash_ring can be read in a blog post (that explains the idea in greater details):

More information about consistent hashing can be read in these articles:

There is also a wrapper MemcacheRing that extends python-memcache to use consistent hashing for key distribution.


Basic example of usage (for managing memcached instances):

memcache_servers = ['',

ring = HashRing(memcache_servers)
server = ring.get_node('my_key')

Example using weights:

memcache_servers = ['',
weights = {
    '': 1,
    '': 2,
    '': 1

ring = HashRing(memcache_servers, weights)
server = ring.get_node('my_key')

How to use MemcacheRing:

from hash_ring import MemcacheRing
mc = MemcacheRing([''])
mc.set('hello', 'world')
print mc.get('hello')

The code should be clean and simple. Feel free to concat the author if you detect bugs.

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(8.4 kB) Copy SHA256 Hash SHA256
Egg 2.7 Dec 21, 2012
(4.0 kB) Copy SHA256 Hash SHA256
Source None Dec 21, 2012

Supported By

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 Google Google Cloud Servers DreamHost DreamHost Log Hosting