Install & Compatibility
Where this runs
tested against v1.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.002s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.006s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
HashRing
✓ from hashring import HashRing
✗ from hash_ring import HashRing
This quickstart demonstrates how to initialize a HashRing with a list of nodes and retrieve the assigned node for a given key. It also shows how to apply weights to nodes for uneven distribution.
from hash_ring import HashRing
# Define a list of nodes (e.g., server addresses)
nodes = ['server1.example.com', 'server2.example.com', 'server3.example.com']
# Create a consistent hash ring
ring = HashRing(nodes)
# Get the node responsible for a specific key
key = "user:12345:data"
assigned_node = ring.get_node(key)
print(f"Key '{key}' is assigned to node: {assigned_node}")
# Example with weights
weighted_nodes = {
'server1.example.com': 1,
'server2.example.com': 2, # server2 gets twice the weight
'server3.example.com': 1
}
weighted_ring = HashRing(weighted_nodes)
assigned_node_weighted = weighted_ring.get_node(key)
print(f"Key '{key}' is assigned to weighted node: {assigned_node_weighted}")
Debug
Known issues
breakingThe library internally uses MD5 as its hashing function. MD5 is cryptographically broken and is unsuitable for security-sensitive applications like password storage or digital signatures due to known collision vulnerabilities.fixAvoid using this library for any security-critical hashing. For secure hashing, use Python's `hashlib` module with algorithms like SHA-256 or SHA3. Consider alternative consistent hashing libraries that allow custom, stronger hash functions.
affects: <=1.5.1
deprecatedThe library's last release (1.5.1) was in April 2015. This indicates that the project is not actively maintained, which may lead to compatibility issues with newer Python versions and a lack of updates for performance or security enhancements.fixFor new projects or if active maintenance is crucial, consider using more current and actively maintained consistent hashing libraries such as `uhashring`.
affects: All versions
gotchaThis library (`hashring`) should not be confused with `uhashring`, another popular and more actively maintained consistent hashing library. While both provide similar functionality, they are distinct projects with different import paths and maintenance statuses.fixEnsure you are installing and importing the correct library (`pip install hashring` for this library, `pip install uhashring` for the alternative). The import for this library is `from hash_ring import HashRing`, while for `uhashring` it's `from uhashring import HashRing`.
affects: All versions
gotchaPython's built-in `hash()` function is non-deterministic across different interpreter runs for strings and other types due to hash randomization (a security feature). This makes it unsuitable for consistent hashing across processes or restarts. `hashring` uses MD5 for its consistent hashing, which is deterministic.fixDo not attempt to replace `hashring`'s internal hashing with Python's built-in `hash()` if cross-process consistency is required. For deterministic (but not necessarily cryptographically secure) hashing, use functions from the `hashlib` module directly if you need a custom hashing strategy.
affects: All Python 3 versions
Upgrade
Version history
1.5.1latest on PyPI · released Apr 14, 2015
Audit
Dependencies
No dependency data recorded yet.