{"library":"requests-sse","title":"Requests-SSE Client","description":"requests-sse is a Python client library for Server-Sent Events (SSE), built on top of the popular 'requests' HTTP library. It provides an `EventSource` object for consuming event streams, handling reconnections and message parsing according to the WHATWG SSE specification. The current stable version is 0.5.3, with a beta 0.6.0b0 indicating an upcoming major release. The library generally follows an active release cadence with minor updates and bug fixes.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install requests-sse"],"cli":null},"imports":["from requests_sse import EventSource","from requests_sse import MessageEvent"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom requests_sse import EventSource\n\n# Example of a public SSE endpoint (Wikimedia recent changes stream)\nSSE_ENDPOINT = os.environ.get('SSE_URL', 'https://stream.wikimedia.org/v2/stream/recentchange')\n\ntry:\n    with EventSource(SSE_ENDPOINT) as es:\n        print(f\"Connected to SSE stream: {SSE_ENDPOINT}\")\n        message_count = 0\n        for event in es:\n            if event.event == \"message\":\n                print(f\"Received message: ID={event.id}, Type='{event.type}', Data='{event.data[:100]}...' \")\n            else:\n                print(f\"Received event '{event.event}': ID={event.id}, Data='{event.data[:100]}...' \")\n            message_count += 1\n            # For demonstration, break after receiving 3 messages\n            if message_count >= 3:\n                break\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to connect to a Server-Sent Events stream using `EventSource` and iterate over incoming `MessageEvent` objects. It uses the `with` statement for proper resource management and shows how to access event properties like `id`, `event` (type), and `data`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}