{"id":18683417,"url":"https://github.com/narasimha1997/redis-pydict","last_synced_at":"2025-06-25T08:06:42.768Z","repository":{"id":44386157,"uuid":"512116584","full_name":"Narasimha1997/redis-pydict","owner":"Narasimha1997","description":"A python dictionary that uses Redis as in-memory storage backend to facilitate distributed computing applications development.","archived":false,"fork":false,"pushed_at":"2023-06-22T02:42:00.000Z","size":46,"stargazers_count":22,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-16T07:50:34.820Z","etag":null,"topics":["backend","distributed-systems","hashtable","message-queue","microservice","python","python3","redis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Narasimha1997.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-07-09T06:56:29.000Z","updated_at":"2025-05-15T22:17:57.000Z","dependencies_parsed_at":"2025-04-12T04:31:38.716Z","dependency_job_id":"f0158cbe-27c7-4b9b-bda5-26ca4a3fa250","html_url":"https://github.com/Narasimha1997/redis-pydict","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Narasimha1997/redis-pydict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fredis-pydict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fredis-pydict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fredis-pydict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fredis-pydict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Narasimha1997","download_url":"https://codeload.github.com/Narasimha1997/redis-pydict/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narasimha1997%2Fredis-pydict/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261832677,"owners_count":23216497,"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":["backend","distributed-systems","hashtable","message-queue","microservice","python","python3","redis"],"created_at":"2024-11-07T10:14:35.654Z","updated_at":"2025-06-25T08:06:42.744Z","avatar_url":"https://github.com/Narasimha1997.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redis-pydict\nA python dictionary that uses Redis as in-memory storage backend to facilitate distributed computing applications development. This library is a small wrapper around Redis providing a dictionary like class that acts as a drop-in replacement for python dict, but stores data in Redis instead of local program memory, thus key-value pairs written into the python dictionary can be used by other programs that are connected to the same Redis instance / cluster anywhere over the network. The library also provides wrapper around Redis Pub-Sub using which processes can publish and wait for events when new keys are added to the dictionary.\n\n### Installation\n1. From source:\n```bash\ngit clone git@github.com:Narasimha1997/redis-pydict.git\ncd redis-pydict\npip3 install -e .\n```\nor \n\n```bash\npip3 install git+https://github.com/Narasimha1997/redis-pydict#egg=redis-pydict\n```\n\n2. From PIP\n```bash\npip3 install redis-pydict\n```\n\n### Usage\n1. Creating the instance of RedisPyDict\n```python\nfrom redis_pydict import PyRedisDict\n\nredis_dict = PyRedisDict(\n    host='localhost',     # redis host\n    port=6379,            # redis port\n    db=0,                 # redis db (0-15)\n    password=None,        # password if using password auth\n    namespace=\"\",         # namespace: this is the key prefix, every key inserted into the dict will be prefixed with this namespace string when inserting into Redis, this provides some degree of isolation between namespaces\n    custom=None  # use a custom connection, pass a Redis/Redis cluster connection object manually, parameters like `host`, `port`, `db` and `password` will be ignored if this is not None\n)\n```\n\n2. Supported functions:\n`PyRedisDict` is a replacement for dict, and it supports most of the dictionary methods:\n```\n\u003e\u003e\u003e dir(redis_dict)\n['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_iter_internal', '_iter_items', '_scan_iter', 'clear', 'enable_publish', 'get', 'items', 'items_matching', 'iter_matching', 'key_namespace', 'keys', 'notification_id', 'redis', 'set_notification_id', 'set_notification_mode', 'subscribe_to_key_events', 'to_dict', 'update', 'values']\n```\n\n3. Publish and subscribe to key set events\n`PyRedisDict` can also send key set events when enabled, by default it is not enabled. You can enable it by calling `set_notification_mode(true)` and `set_notification_id(unique_id)`. Every instance of `PyRedisDict` should be set to a unqiue ID to help diffreniciating with each of them. Here is an example\n\nOn the sender side:\n\n```python\n# enable notifications\nredis_dict.set_notification_mode(True)\n\n# set a unique id\nredis_dict.set_notification_id('myprocess1')\n\n# now this operation will also publish an event which can be captured by subscribers\nredis_dict['key'] = \"Hello\"\n```\n\nOn receiver side:\n```python\n# this will listen for key set events for key 'key' in the given namespace\nfor (key, notification_id, value) in redis_dict.subscribe_to_key_events(pattern=\"key\"):\n    print(key, notification_id, value)\n\n# optionally you can also use a regex pattern, this example listen for all key events matching pattern key*\nfor (key, notification_id, value) in redis_dict.subscribe_to_key_events(pattern=\"key*\"):\n    print(key, notification_id, value)\n```\n\n### Examples:\n1. Basic set and get\n```python\ndef test_basic_get_set():\n   d = PyRedisDict(namespace=\"mykeyspace\")\n\n   d.clear()\n   d['none'] = None\n   d['int'] = 10\n   d['float'] = 20.131\n   d['array'] = [10, 20, 30]\n   d['hashmap'] = {'name': 'prasanna', 'meta': {'age': 24, 'hobbies': ['gaming']}}\n\n   # assert values\n   assert d['int'] == 10\n   assert d['float'] == 20.131\n   assert d['array'] == [10, 20, 30]\n   assert (d['hashmap']['name'] == 'prasanna') and (d['hashmap']['meta']['age'] == 24)\n   assert (d['none'] == None)\n\n   d.clear()\n```\n\n2. Custom objects\n```python\ndef test_custom_class_get_set():\n   d = PyRedisDict(namespace=\"mykeyspace\")\n\n   d.clear()\n   d['obj'] = CustomClass()\n\n   assert d['obj'].add() == (10 + 20 + 30)\n   d.clear()\n```\n**Note**: `PyRedisDict` uses `cPickle` for custom objects.\n\n3. Iterations\n```python\ndef test_iterations():\n\n   d = PyRedisDict(namespace=\"mykeyspace2\")\n   d.clear()\n   d['mykey_none'] = None\n   d['mykey_int'] = 10\n   d['mykey_float'] = 20.131\n   d['array'] = [10, 20, 30]\n   d['hashmap'] = {'name': 'prasanna', 'meta': {'age': 24, 'hobbies': ['gaming']}}\n\n   # assert values\n   assert len(d) == 5\n   assert len(d.items()) == 5\n\n   # find by prefix\n   assert len(d.items_matching('mykey*')) == 3\n   d.clear()\n```\n\n4. Key deletion\n```python\ndef test_deletion():\n\n   d = PyRedisDict(namespace=\"mykeyspace3\")\n\n   d.clear()\n   d['x1'] = CustomClass()\n   d['x2'] = CustomClass()\n   d['x3'] = CustomClass()\n   d['x4'] = CustomClass()\n   d['x4'] = CustomClass()\n\n   assert 'x1' in d\n   del d['x1']\n\n   assert 'x1' not in d\n\n   d.clear()\n   assert len(d) == 0\n```\n\n5. Converting to/from dict\n```python\ndef test_conversions():\n   d = PyRedisDict(namespace=\"mykeyspace\")\n\n   d.clear()\n\n   d['mykey_none'] = None\n   d['mykey_int'] = 10\n   d['mykey_float'] = 20.131\n   d['array'] = [10, 20, 30]\n   d['hashmap'] = {'name': 'prasanna', 'meta': {'age': 24, 'hobbies': ['gaming']}}\n\n   assert len(d.to_dict()) == 5\n\n   normal_dict = {\"mykey_1\": 10, \"mykey_2\": 20, \"mykey_3\": \"hello\", \"array\": [50, 60, 70]}\n   d.update(normal_dict)\n\n   assert len(d) == (5 + 3) # another key is duplicate (array)\n   assert d['array'] == [50, 60, 70]\n   d.clear()\n```\n\n### Running tests\nThis project uses `pytest` for testing. Instal pytest and run `pytest` to validate tests, make sure you set-up Redis locally to test the process.\n\n### Contributions\nFeel free to try this library, suggest changes, raise issues, send PRs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarasimha1997%2Fredis-pydict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarasimha1997%2Fredis-pydict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarasimha1997%2Fredis-pydict/lists"}