{"id":13619659,"url":"https://github.com/redis/hiredis-py","last_synced_at":"2025-05-13T20:15:14.278Z","repository":{"id":1355651,"uuid":"1303362","full_name":"redis/hiredis-py","owner":"redis","description":"Python wrapper for hiredis","archived":false,"fork":false,"pushed_at":"2025-04-24T18:04:02.000Z","size":224,"stargazers_count":502,"open_issues_count":9,"forks_count":101,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-28T11:52:25.007Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","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/redis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2011-01-28T16:27:28.000Z","updated_at":"2025-04-24T10:10:50.000Z","dependencies_parsed_at":"2025-03-16T21:21:55.623Z","dependency_job_id":"d861db00-9123-441c-9460-ea086886a7f4","html_url":"https://github.com/redis/hiredis-py","commit_stats":{"total_commits":203,"total_committers":44,"mean_commits":4.613636363636363,"dds":0.6600985221674878,"last_synced_commit":"c1eefbdb76614435f7433207bf385ba8cb930b60"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fhiredis-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fhiredis-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fhiredis-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fhiredis-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis","download_url":"https://codeload.github.com/redis/hiredis-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251462804,"owners_count":21593431,"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-08-01T21:00:46.566Z","updated_at":"2025-05-13T20:15:14.260Z","avatar_url":"https://github.com/redis.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# hiredis-py\n\n[![Build Status](https://github.com/redis/hiredis-py/actions/workflows/integration.yaml/badge.svg)](https://github.com/redis/hiredis-py/actions/workflows/integration.yaml)\n[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n[![pypi](https://badge.fury.io/py/hiredis.svg)](https://pypi.org/project/hiredis/)\n\nPython extension that wraps protocol parsing code in [hiredis][hiredis].\nIt primarily speeds up parsing of multi bulk replies.\n\n[hiredis]: http://github.com/redis/hiredis\n\n## How do I Redis?\n\n[Learn for free at Redis University](https://university.redis.com/)\n\n[Build faster with the Redis Launchpad](https://launchpad.redis.com/)\n\n[Try the Redis Cloud](https://redis.com/try-free/)\n\n[Dive in developer tutorials](https://developer.redis.com/)\n\n[Join the Redis community](https://redis.com/community/)\n\n[Work at Redis](https://redis.com/company/careers/jobs/)\n\n## Install\n\nhiredis-py is available on [PyPI](https://pypi.org/project/hiredis/), and can be installed via:\n\n```bash\npip install hiredis\n```\n## Building and Testing\n\nBuilding this repository requires a recursive checkout of submodules, and building hiredis. The following example shows how to clone, compile, and run tests. Please note - you will need the gcc installed.\n\n```bash\ngit clone --recurse-submodules https://github.com/redis/hiredis-py\npython setup.py build_ext --inplace\npython -m pytest\n```\n\n### Requirements\n\nhiredis-py requires **Python 3.8+**.\n\nMake sure Python development headers are available when installing hiredis-py.\nOn Ubuntu/Debian systems, install them with `apt-get install python3-dev`.\n\n## Usage\n\nThe `hiredis` module contains the `Reader` class. This class is responsible for\nparsing replies from the stream of data that is read from a Redis connection.\nIt does not contain functionality to handle I/O.\n\n### Reply parser\n\nThe `Reader` class has two methods that are used when parsing replies from a\nstream of data. `Reader.feed` takes a string argument that is appended to the\ninternal buffer. `Reader.gets` reads this buffer and returns a reply when the\nbuffer contains a full reply. If a single call to `feed` contains multiple\nreplies, `gets` should be called multiple times to extract all replies.\n\nExample:\n\n```python\n\u003e\u003e\u003e reader = hiredis.Reader()\n\u003e\u003e\u003e reader.feed(\"$5\\r\\nhello\\r\\n\")\n\u003e\u003e\u003e reader.gets()\nb'hello'\n```\n\nWhen the buffer does not contain a full reply, `gets` returns `False`.\nThis means extra data is needed and `feed` should be called again before calling\n`gets` again. Alternatively you could provide custom sentinel object via parameter,\nwhich is useful for RESP3 protocol where native boolean types are supported:\n\nExample:\n\n```python\n\u003e\u003e\u003e reader.feed(\"*2\\r\\n$5\\r\\nhello\\r\\n\")\n\u003e\u003e\u003e reader.gets()\nFalse\n\u003e\u003e\u003e reader.feed(\"$5\\r\\nworld\\r\\n\")\n\u003e\u003e\u003e reader.gets()\n[b'hello', b'world']\n\u003e\u003e\u003e reader = hiredis.Reader(notEnoughData=Ellipsis)\n\u003e\u003e\u003e reader.gets()\nEllipsis\n```\n\n#### Unicode\n\n`hiredis.Reader` is able to decode bulk data to any encoding Python supports.\nTo do so, specify the encoding you want to use for decoding replies when\ninitializing it:\n\n```python\n\u003e\u003e\u003e reader = hiredis.Reader(encoding=\"utf-8\", errors=\"strict\")\n\u003e\u003e\u003e reader.feed(b\"$3\\r\\n\\xe2\\x98\\x83\\r\\n\")\n\u003e\u003e\u003e reader.gets()\n'☃'\n```\n\nDecoding of bulk data will be attempted using the specified encoding and\nerror handler. If the error handler is `'strict'` (the default), a\n`UnicodeDecodeError` is raised when data cannot be dedcoded. This is identical\nto Python's default behavior. Other valid values to `errors` include\n`'replace'`, `'ignore'`, and `'backslashreplace'`. More information on the\nbehavior of these error handlers can be found\n[here](https://docs.python.org/3/howto/unicode.html#the-string-type).\n\n\nWhen the specified encoding cannot be found, a `LookupError` will be raised\nwhen calling `gets` for the first reply with bulk data.\n\n#### Error handling\n\nWhen a protocol error occurs (because of multiple threads using the same\nsocket, or some other condition that causes a corrupt stream), the error\n`hiredis.ProtocolError` is raised. Because the buffer is read in a lazy\nfashion, it will only be raised when `gets` is called and the first reply in\nthe buffer contains an error. There is no way to recover from a faulty protocol\nstate, so when this happens, the I/O code feeding data to `Reader` should\nprobably reconnect.\n\nRedis can reply with error replies (`-ERR ...`). For these replies, the custom\nerror class `hiredis.ReplyError` is returned, **but not raised**.\n\nWhen other error types should be used (so existing code doesn't have to change\nits `except` clauses), `Reader` can be initialized with the `protocolError` and\n`replyError` keywords. These keywords should contain a *class* that is a\nsubclass of `Exception`. When not provided, `Reader` will use the default\nerror types.\n\n## Benchmarks\n\nThe repository contains a benchmarking script in the `benchmark` directory,\nwhich uses [gevent](http://gevent.org/) to have non-blocking I/O and redis-py\nto handle connections. These benchmarks are done with a patched version of\nredis-py that uses hiredis-py when it is available.\n\nAll benchmarks are done with 10 concurrent connections.\n\n* SET key value + GET key\n  * redis-py: 11.76 Kops\n  * redis-py *with* hiredis-py: 13.40 Kops\n  * improvement: **1.1x**\n\nList entries in the following tests are 5 bytes.\n\n* LRANGE list 0 **9**:\n  * redis-py: 4.78 Kops\n  * redis-py *with* hiredis-py: 12.94 Kops\n  * improvement: **2.7x**\n* LRANGE list 0 **99**:\n  * redis-py: 0.73 Kops\n  * redis-py *with* hiredis-py: 11.90 Kops\n  * improvement: **16.3x**\n* LRANGE list 0 **999**:\n  * redis-py: 0.07 Kops\n  * redis-py *with* hiredis-py: 5.83 Kops\n  * improvement: **83.2x**\n\nThroughput improvement for simple SET/GET is minimal, but the larger multi bulk replies\nget, the larger the performance improvement is.\n\n## License\n\nThis code is released under the BSD license, after the license of hiredis.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fhiredis-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis%2Fhiredis-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fhiredis-py/lists"}