Registry / azure / azure-communication-chat

azure-communication-chat

JSON →
library1.3.0pypypi✓ verified 85d ago

Microsoft Azure Communication Chat Client Library for Python enables developers to integrate real-time chat capabilities into applications. Current version is 1.3.0, requires Python >=3.8, and follows a monthly release cadence aligned with the Azure SDK for Python.

pip install azure-communication-chat
INSTALL
IMPORT
SIG · AZURE-COMMUNICATIO
A
azure-communication-chat
azurepythonv1.3.0
Install
2.4s avg
Import
427ms
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.3.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.446s · 24.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.408s · 25MB
23MB installed
● package 23MB
Code
Verified usage

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

ChatClient
from azure.communication.chat import ChatClient
CommunicationTokenCredential
from azure.communication.chat import CommunicationTokenCredential
from azure.core.credentials import AccessToken
AccessToken is used internally, but the correct class for chat is CommunicationTokenCredential

Creates a chat thread with two participants using an endpoint and user access token.

import os from azure.communication.chat import ChatClient, CommunicationTokenCredential endpoint = os.environ.get("COMMUNICATION_SERVICES_ENDPOINT", "") user_access_token = os.environ.get("USER_ACCESS_TOKEN", "") credential = CommunicationTokenCredential(user_access_token) chat_client = ChatClient(endpoint, credential) # Create a chat thread from azure.communication.chat import CreateChatThreadRequest create_chat_thread_request = CreateChatThreadRequest( topic="Hello World!", members=[ {"user": "8:acs:...", "display_name": "User1"}, {"user": "8:acs:...", "display_name": "User2"} ] ) result = chat_client.create_chat_thread(create_chat_thread_request) print(f"Chat thread created with ID: {result.chat_thread.id}")
Debug
Known issues
gotchaChatClient constructor requires a CommunicationTokenCredential, not an AzureKeyCredential or DefaultAzureCredential. Using the wrong credential type will raise a TypeError.
fix
Use CommunicationTokenCredential with a valid user access token obtained from the Communication Identity API.
affects: all
gotchaThe endpoint URL must include the trailing forward slash (e.g., 'https://<resource>.communication.azure.com/'). Missing the slash will cause an InvalidURL error.
fix
Ensure the endpoint string ends with a '/'.
affects: all
breakingIn version 1.2.0, the 'members' parameter in CreateChatThreadRequest changed from a list of dicts to a list of ChatParticipant objects. Using plain dicts will raise an AttributeError.
fix
Use azure.communication.chat.ChatParticipant objects with 'user', 'display_name', and 'share_history_time'.
affects: >=1.2.0
gotchaThe CommunicationTokenCredential does not auto-refresh tokens. For long-lived applications, implement token refresh logic and wrap it in a callback.
fix
Use the overloaded constructor that accepts a callable for token refresh: CommunicationTokenCredential(token_refresh_callback).
affects: all
Errors
Common errors & fixes
AttributeError: module 'azure.communication.chat' has no attribute 'ChatThreadClient'
In older versions (pre-1.1.0), ChatThreadClient was accessed differently. In 1.2.0+, ChatThreadClient is obtained via ChatClient.get_chat_thread_client().
fix
Use chat_client.get_chat_thread_client(thread_id) to obtain a ChatThreadClient instance.
TypeError: Object of type 'list' is not JSON serializable
Passing a plain Python list for 'members' in CreateChatThreadRequest instead of a list of ChatParticipant objects.
fix
Create ChatParticipant objects: from azure.communication.chat import ChatParticipant; members = [ChatParticipant(user=..., display_name=...)]
HttpRequestError: (InvalidURL) Invalid URL
The endpoint URL is missing a trailing slash or is incorrectly formatted.
fix
Ensure the endpoint ends with '/', e.g., 'https://myresource.communication.azure.com/'.
Upgrade
Version history
1.3.0latest on PyPI · released Apr 11, 2024
Audit
Dependencies
azure-corerequiredCore Azure SDK dependency for HTTP pipeline, authentication, and logging
azure-communication-identityrequiredRequired for creating and managing user access tokens for chat
Agent activity
45 hits · last 30 days
node
38
Amazon
1
OpenAI (training)
1
Resources
azure-communication-chat — pip install azure-communication-chat · libregistry