uhashring is a full-featured pure Python library for consistent hashing, primarily used in distributed systems, caches, and databases to efficiently distribute data across nodes. It aims to prevent total reshuffling of key-node mappings when nodes are added or removed. The library offers Ketama compatibility, customizable hash and weight functions, and supports instance-oriented usage. The current version is 2.4, with releases occurring periodically, as evidenced by its PyPI update in April 2025 and ongoing GitHub activity. [1, 2]
pip install uhashringVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `HashRing` with a list of nodes, find the responsible node for a specific key, and dynamically add or remove nodes. It also shows how to check the current configuration and the distribution of 'points' on the ring among the nodes. [1, 2]
For Ketama compatibility, explicitly initialize `HashRing(hash_fn='ketama', vnodes=40, replicas=4, ...)` to restore the previous behavior. Otherwise, be aware of the new default hashing algorithm and vnode count. [1]
Ensure your project runs on Python 3.8 or newer. If Python 2 support is critical, you must use `uhashring==1.1.0` (or `uhashring==1.2` for the last version with Py2 support, but newer features might be missing). [1]
Consider if strict Ketama compatibility is necessary. For better performance on dynamic node topology, rely on the default MD5 hash function or use another custom hash function that doesn't require full ring regeneration. [1]
Carefully design and test your `weight_fn` if you choose to implement one. Ensure it accurately reflects the capacity or desired load of each node. [1]
pip install uhashring
from uhashring import HashRing
Ensure that nodes are passed as strings (e.g., `'my_node'`) or dictionaries (e.g., `{'instance': 'my_node_instance', 'host': '127.0.0.1'}`) to `add_node` or `add_nodes`.No dependency data recorded yet.