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!

Consistent hashing for Python

Project Description

Copyright (c) 2010 by Joachim Bauch,

python-continuum provides a function to do consistent hashing. See wikipedia [1] for more informations about this technique.

First we need the continuum object that serves as storage for server informations and can later be used to resolve keys:

>>> from continuum import Continuum
>>> c = Continuum()

Empty continuums obviously can’t be queried:

>>> c.resolve('my-key1')
Traceback (most recent call last):
IndexError: empty continuum

Add the server objects that are available as backends:

>>> c.add_server('', 8080)
<Server "", capacity=1>
>>> c.add_server('', 8080)
<Server "", capacity=1>

You can also specify different capacities of the server to priorize them (this defaults to 1):

>>> c.add_server('', 8080, 2)
<Server "", capacity=2>

Server objects can also be removed:

>>> server = c.add_server('', 8080)
>>> c.remove_server(server)
>>> len(c)

Please note that a server can only be added once:

>>> c.add_server('', 8080)
Traceback (most recent call last):
TypeError: server already added

After all servers have been added, the continuum can be queried for the server that should be used for a given (string) key:

>>> c.resolve('my-first-key')
<Server "", capacity=1>
>>> c.resolve('my-other-key')
<Server "", capacity=2>

Release History

This version
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
(5.7 kB) Copy SHA256 Hash SHA256
Egg 2.6 Nov 15, 2010
(17.9 kB) Copy SHA256 Hash SHA256
Source None Nov 15, 2010

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