{"id":15681427,"url":"https://github.com/fancycode/python-continuum","last_synced_at":"2025-05-07T12:13:12.319Z","repository":{"id":138755061,"uuid":"1079783","full_name":"fancycode/python-continuum","owner":"fancycode","description":"Consistent hashing for Python.","archived":false,"fork":false,"pushed_at":"2014-09-21T20:19:06.000Z","size":135,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T12:13:06.197Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.joachim-bauch.de/projects/python-continuum/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fancycode.png","metadata":{"files":{"readme":"README.txt","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-11-14T23:33:19.000Z","updated_at":"2023-01-02T16:34:12.000Z","dependencies_parsed_at":"2023-03-12T16:36:07.079Z","dependency_job_id":null,"html_url":"https://github.com/fancycode/python-continuum","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fancycode%2Fpython-continuum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fancycode%2Fpython-continuum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fancycode%2Fpython-continuum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fancycode%2Fpython-continuum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fancycode","download_url":"https://codeload.github.com/fancycode/python-continuum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252873889,"owners_count":21817715,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T16:54:22.122Z","updated_at":"2025-05-07T12:13:12.290Z","avatar_url":"https://github.com/fancycode.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"python-continuum - Consistent hashing\n========================================================================\n\nCopyright (c) 2010 by Joachim Bauch, mail@joachim-bauch.de\nhttp://www.joachim-bauch.de/projects/python-continuum/\n\npython-continuum provides a function to do consistent hashing. See\nwikipedia [1]_ for more informations about this technique.\n\nFirst we need the continuum object that serves as storage for server\ninformations and can later be used to resolve keys::\n\n\t\u003e\u003e\u003e from continuum import Continuum\n\t\u003e\u003e\u003e c = Continuum()\n\nEmpty continuums obviously can't be queried::\n\n\t\u003e\u003e\u003e c.resolve('my-key1')\n\tTraceback (most recent call last):\n\t...\n\tIndexError: empty continuum\n\nAdd the server objects that are available as backends::\n\n\t\u003e\u003e\u003e c.add_server('192.168.0.1', 8080)\n\t\u003cServer \"192.168.0.1:8080\", capacity=1\u003e\n\t\u003e\u003e\u003e c.add_server('192.168.0.2', 8080)\n\t\u003cServer \"192.168.0.2:8080\", capacity=1\u003e\n\nYou can also specify different capacities of the server to priorize\nthem (this defaults to 1)::\n\n\t\u003e\u003e\u003e c.add_server('192.168.0.3', 8080, 2)\n\t\u003cServer \"192.168.0.3:8080\", capacity=2\u003e\n\nServer objects can also be removed::\n\n\t\u003e\u003e\u003e server = c.add_server('192.168.0.4', 8080)\n\t\u003e\u003e\u003e c.remove_server(server)\n\t\u003e\u003e\u003e len(c)\n\t3\n\nPlease note that a server can only be added once::\n\n\t\u003e\u003e\u003e c.add_server('192.168.0.2', 8080)\n\tTraceback (most recent call last):\n\t...\n\tTypeError: server already added\n\nAfter all servers have been added, the continuum can be queried for the\nserver that should be used for a given (string) key::\n\n\t\u003e\u003e\u003e c.resolve('my-first-key')\n\t\u003cServer \"192.168.0.1:8080\", capacity=1\u003e\n\t\u003e\u003e\u003e c.resolve('my-other-key')\n\t\u003cServer \"192.168.0.3:8080\", capacity=2\u003e\n\n\n.. [1] http://en.wikipedia.org/wiki/Consistent_hashing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffancycode%2Fpython-continuum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffancycode%2Fpython-continuum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffancycode%2Fpython-continuum/lists"}