{"id":34725762,"url":"https://github.com/suqingdong/drf_sse","last_synced_at":"2026-05-26T10:32:51.127Z","repository":{"id":231005049,"uuid":"780368136","full_name":"suqingdong/drf_sse","owner":"suqingdong","description":"SSE(Server-Sent Events) for DjangoRestFramework","archived":false,"fork":false,"pushed_at":"2024-04-02T03:12:34.000Z","size":143,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-13T21:10:28.347Z","etag":null,"topics":["djangorestframework","drf","sse"],"latest_commit_sha":null,"homepage":"https://suqingdong.github.io/drf_sse/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suqingdong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-04-01T10:25:39.000Z","updated_at":"2026-02-21T22:06:56.000Z","dependencies_parsed_at":"2024-04-02T03:26:53.131Z","dependency_job_id":null,"html_url":"https://github.com/suqingdong/drf_sse","commit_stats":null,"previous_names":["suqingdong/drf_sse"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/suqingdong/drf_sse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suqingdong%2Fdrf_sse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suqingdong%2Fdrf_sse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suqingdong%2Fdrf_sse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suqingdong%2Fdrf_sse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suqingdong","download_url":"https://codeload.github.com/suqingdong/drf_sse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suqingdong%2Fdrf_sse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33517111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T03:12:49.672Z","status":"ssl_error","status_checked_at":"2026-05-26T03:12:47.976Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["djangorestframework","drf","sse"],"created_at":"2025-12-25T02:27:07.063Z","updated_at":"2026-05-26T10:32:51.109Z","avatar_url":"https://github.com/suqingdong.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SSE(Server-Sent Events) for DjangoRestFramework\n\n## Installation\n\n```bash\npython3 -m pip install drf-sse\n```\n\n## Usage\n\n##### 1. Edit your `setting.py`:\n\n```python\nINSTALL_APPS += [\n    'rest_framework',\n    'corsheaders',\n    'drf_sse',\n]\n\nMIDDLEWARE.insert(0, 'corsheaders.middleware.CorsMiddleware')\nCORS_ALLOW_ALL_ORIGINS = True\n\n# SSE configuration\n# SSE_RESPONSE_MODE = 'add'  # [optional, default: \"chunk\"]\nSSE_ENCODE_BASE64 = True     # [optional, default: False]\n```\n\n##### 2. Use in your views:\n\n```python\nimport time\n\nfrom drf_sse import SSEMixin, SSEResponse\nfrom rest_framework.views import APIView\n\nclass MyView(SSEMixin, APIView):\n    def get(self, request, format=None):\n\n        def iter_data():\n            iter_data = 'This is a server-sent events response'.split()\n            for part in iter_data:\n                yield part\n                time.sleep(1)\n\n        return SSEResponse(iter_data())\n        # return SSEResponse(iter_data(), mode='chunk', encode=False)  # will overwrite settings\n```\n\n##### 3. Test from the frontend:\n\n- `SSE_ENCODE_BASE64 = False`\n\n```html\n\u003cbody\u003e\n    \u003cp id=\"result\"\u003e\u003c/p\u003e\n\u003c/body\u003e\n\u003cscript\u003e\n    const eventSource = new EventSource('http://127.0.0.1:8000/sse/')\n    eventSource.onmessage = (event) =\u003e {\n        console.log(event)\n        document.getElementById('result').innerHTML += event.data + ' '\n    }\n    eventSource.onopen = () =\u003e {\n        console.log('sse opened.')\n    }\n    eventSource.addEventListener('end', () =\u003e {\n        eventSource.close()\n        console.log('sse closed.')\n    })\n\u003c/script\u003e\n```\n\n\u003cdetails\u003e\n\u003csummary\u003ePreview\u003c/summary\u003e\n\u003cimg src=\"https://suqingdong.github.io/drf_sse/src/sse.png\" widt=\"60%\"/\u003e\n\u003c/details\u003e\n\n---\n\n- `SSE_ENCODE_BASE64 = True`\n\n```html\n\u003cbody\u003e\n    \u003cp id=\"result\"\u003e\u003c/p\u003e\n\u003c/body\u003e\n\u003cscript\u003e\n    const base64DecodeAndUtf8Decode = (encodedStr) =\u003e {\n        const textDecoder = new TextDecoder();\n        const bytes = Uint8Array.from(atob(encodedStr), c =\u003e c.charCodeAt(0));\n        return textDecoder.decode(bytes);\n    }\n\n    const eventSource = new EventSource('http://127.0.0.1:8000/sse/')\n    eventSource.onmessage = (event) =\u003e {\n        console.log(event)\n        document.getElementById('result').innerHTML += base64DecodeAndUtf8Decode(event.data) + ' '\n    }\n    eventSource.onopen = () =\u003e {\n        console.log('sse opened.')\n    }\n    eventSource.addEventListener('end', () =\u003e {\n        eventSource.close()\n        console.log('sse closed.')\n    })\n\u003c/script\u003e\n```\n\n\u003cdetails\u003e\n\u003csummary\u003ePreview\u003c/summary\u003e\n\u003cimg src=\"https://suqingdong.github.io/drf_sse/src/sse-encode.png\" widt=\"60%\"/\u003e\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuqingdong%2Fdrf_sse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuqingdong%2Fdrf_sse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuqingdong%2Fdrf_sse/lists"}