{"id":5649,"library":"launchdarkly-eventsource","title":"LaunchDarkly SSE Client","description":"The `launchdarkly-eventsource` library is a Python client for Server-Sent Events (SSE), enabling applications to subscribe to and process real-time events from an SSE server. It is currently at version 1.5.1 and maintains an active release cadence with regular updates and bug fixes, typically every few months.","status":"active","version":"1.5.1","language":"en","source_language":"en","source_url":"https://github.com/launchdarkly/python-eventsource","tags":["sse","eventsource","server-sent events","launchdarkly","client","real-time"],"install":[{"cmd":"pip install launchdarkly-eventsource","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"symbol":"EventSource","correct":"from ld_eventsource import EventSource"},{"note":"Used for type hinting and accessing event details.","symbol":"MessageEvent","correct":"from ld_eventsource import MessageEvent"}],"quickstart":{"code":"import os\nimport time\nfrom ld_eventsource import EventSource, MessageEvent\n\n# Replace with your SSE endpoint\nSSE_URL = os.environ.get('SSE_ENDPOINT', 'http://localhost:8080/events')\n\ndef handle_event(event: MessageEvent):\n    print(f\"Received event: ID={event.last_event_id}, Type={event.event_type}, Data={event.data}\")\n\ndef handle_error(error):\n    print(f\"Error: {error}\")\n\ndef handle_open():\n    print(\"Connection opened.\")\n\ndef handle_closed():\n    print(\"Connection closed.\")\n\ndef main():\n    print(f\"Connecting to SSE_URL: {SSE_URL}\")\n    es = None\n    try:\n        es = EventSource(SSE_URL)\n        es.on_message += handle_event\n        es.on_error += handle_error\n        es.on_open += handle_open\n        es.on_closed += handle_closed\n\n        print(\"Starting EventSource (listening for 10 seconds for demonstration)...\")\n        # EventSource.start() blocks until connection closes or .close() is called.\n        # In a real application, you might run this in a separate thread.\n        es.start()\n\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n    finally:\n        if es and es.is_running:\n            print(\"Closing EventSource connection.\")\n            es.close()\n        print(\"Exiting.\")\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"This quickstart demonstrates how to connect to an SSE endpoint, register handlers for message, error, open, and close events, and then start listening for events. The `start()` method is blocking, so in a long-running application, it's typically run in a separate thread. For this example, it will attempt to connect and process events until closed."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher. Python 3.8 reached end-of-life on October 7, 2024.","message":"Python 3.8 is no longer supported starting with version 1.3.0. Attempts to install or run on Python 3.8 will fail or result in unexpected behavior.","severity":"breaking","affected_versions":"<1.3.0"},{"fix":"Upgrade your Python environment to 3.8 or higher (and preferably 3.9+ for compatibility with newer versions).","message":"Python 3.7 is no longer supported starting with version 1.2.0. Users on Python 3.7 must upgrade their Python version to use this library.","severity":"breaking","affected_versions":"<1.2.0"},{"fix":"Ensure you are using `launchdarkly-eventsource` version 1.2.3 or newer to leverage the fix for `ssl.wrap_socket` usage.","message":"Older versions (prior to 1.2.3) might encounter issues with deprecated `ssl.wrap_socket` usage when dealing with custom SSL contexts or certain environments, potentially leading to connection failures.","severity":"gotcha","affected_versions":"<1.2.3"}],"env_vars":null,"last_verified":"2026-04-08T00:00:00.000Z","next_check":"2026-07-07T00:00:00.000Z"}