Registry / azure / azure-messaging-webpubsubclient

azure-messaging-webpubsubclient

JSON →
library1.1.0pypypi✓ verified 85d ago

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.

pip install azure-messaging-webpubsubclient
INSTALL
IMPORT
SIG · AZURE-MESSAGING-WE
A
azure-messaging-webpubsubclient
azurepythonv1.1.0
Install
2.5s avg
Import
535ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.562s · 24.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.508s · 25MB
23MB installed
● package 23MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebPubSubClient
from azure.messaging.webpubsubclient import WebPubSubClient
from azure.messaging.webpubsub import WebPubSubClient
The package is azure-messaging-webpubsubclient, not azure-messaging-webpubsub.
WebPubSubClientCredential
from azure.messaging.webpubsubclient.models import WebPubSubClientCredential
Wrong import path leads to ImportError.

Minimal setup to connect to Azure Web PubSub using a connection string.

import os from azure.messaging.webpubsubclient import WebPubSubClient from azure.messaging.webpubsubclient.models import WebPubSubClientCredential connection_string = os.environ.get('WEBPUBSUB_CONNECTION_STRING', '') client = WebPubSubClient(connection_string=connection_string) client.open() # ... use client client.close()
Debug
Known issues
breakingIn 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.
fix
Update to 1.1.0 and adapt to async usage if needed, or use the sync wrapper.
affects: <1.0.0
deprecatedThe '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.
fix
Use client.subscribe(event, handler) instead of client.on(event, handler).
affects: 1.0.0 and later
gotchaThe 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.
fix
Set up reconnect options when creating the client, e.g., WebPubSubClient(connection_string=..., reconnect_retry_total=3).
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'WebPubSubClient' from 'azure.messaging.webpubsub'
Incorrect import path; the correct package is azure.messaging.webpubsubclient.
fix
Use: from azure.messaging.webpubsubclient import WebPubSubClient
AttributeError: 'WebPubSubClient' object has no attribute 'on'
The 'on' method was renamed to 'subscribe' in version 1.0.0.
fix
Use client.subscribe(event, handler) instead.
TypeError: __init__() got an unexpected keyword argument 'credential'
The constructor expects either 'connection_string' or 'credential' as a WebPubSubClientCredential object, not a raw credential.
fix
Create a WebPubSubClientCredential object first: from azure.messaging.webpubsubclient.models import WebPubSubClientCredential; credential = WebPubSubClientCredential(...); client = WebPubSubClient(credential=credential)
Upgrade
Version history
1.1.0latest on PyPI · released May 6, 2024
Audit
Dependencies
azure-corerequiredRequired for core Azure SDK functionality (policies, credentials)
websocket-clientrequiredUsed for WebSocket connections
azure-identityoptionalFor authentication using DefaultAzureCredential or other credential types
Agent activity
37 hits · last 30 days
node
32
OpenAI (training)
1
Resources
azure-messaging-webpubsubclient — pip install azure-messaging-webpubsubclient · libregistry