{"id":23332,"library":"azure-messaging-webpubsubclient","title":"Azure Web PubSub Client Library for Python","description":"The Azure Web PubSub Client Library for Python (v1.1.0) enables real-time messaging between clients and a Web PubSub service instance. It supports reliable WebSocket connections, group joins, event handlers, and reconnection. Released under the Azure SDK for Python monorepo, it follows a stable release cadence with regular updates.","status":"active","version":"1.1.0","language":"python","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/webpubsub/azure-messaging-webpubsubclient","tags":["azure","webpubsub","real-time","messaging","websocket"],"install":[{"cmd":"pip install azure-messaging-webpubsubclient","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for core Azure SDK functionality (policies, credentials)","package":"azure-core","optional":false},{"reason":"Used for WebSocket connections","package":"websocket-client","optional":false},{"reason":"For authentication using DefaultAzureCredential or other credential types","package":"azure-identity","optional":true}],"imports":[{"note":"The package is azure-messaging-webpubsubclient, not azure-messaging-webpubsub.","wrong":"from azure.messaging.webpubsub import WebPubSubClient","symbol":"WebPubSubClient","correct":"from azure.messaging.webpubsubclient import WebPubSubClient"},{"note":"Wrong import path leads to ImportError.","wrong":"","symbol":"WebPubSubClientCredential","correct":"from azure.messaging.webpubsubclient.models import WebPubSubClientCredential"}],"quickstart":{"code":"import os\nfrom azure.messaging.webpubsubclient import WebPubSubClient\nfrom azure.messaging.webpubsubclient.models import WebPubSubClientCredential\n\nconnection_string = os.environ.get('WEBPUBSUB_CONNECTION_STRING', '')\nclient = WebPubSubClient(connection_string=connection_string)\nclient.open()\n# ... use client\nclient.close()","lang":"python","description":"Minimal setup to connect to Azure Web PubSub using a connection string."},"warnings":[{"fix":"Update to 1.1.0 and adapt to async usage if needed, or use the sync wrapper.","message":"In version 1.0.0, the client API was redesigned. The old synchronous methods (e.g., send_message) were replaced with an async-first pattern. If you were using preview versions (0.x), your code will break.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use client.subscribe(event, handler) instead of client.on(event, handler).","message":"The 'on' method for event handlers is deprecated in favor of the 'subscribe' method. The old pattern is still supported but will be removed in a future version.","severity":"deprecated","affected_versions":"1.0.0 and later"},{"fix":"Set up reconnect options when creating the client, e.g., WebPubSubClient(connection_string=..., reconnect_retry_total=3).","message":"The client does not automatically reconnect if the server closes the WebSocket with a non-retriable status code. Users must implement their own reconnection logic or use the built-in auto-reconnect utility.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: from azure.messaging.webpubsubclient import WebPubSubClient","cause":"Incorrect import path; the correct package is azure.messaging.webpubsubclient.","error":"ImportError: cannot import name 'WebPubSubClient' from 'azure.messaging.webpubsub'"},{"fix":"Use client.subscribe(event, handler) instead.","cause":"The 'on' method was renamed to 'subscribe' in version 1.0.0.","error":"AttributeError: 'WebPubSubClient' object has no attribute 'on'"},{"fix":"Create a WebPubSubClientCredential object first: from azure.messaging.webpubsubclient.models import WebPubSubClientCredential; credential = WebPubSubClientCredential(...); client = WebPubSubClient(credential=credential)","cause":"The constructor expects either 'connection_string' or 'credential' as a WebPubSubClientCredential object, not a raw credential.","error":"TypeError: __init__() got an unexpected keyword argument 'credential'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}