{"id":23325,"library":"azure-communication-chat","title":"Azure Communication Chat Client Library for Python","description":"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.","status":"active","version":"1.3.0","language":"python","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","communication","chat","messaging","real-time","microsoft"],"install":[{"cmd":"pip install azure-communication-chat","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Core Azure SDK dependency for HTTP pipeline, authentication, and logging","package":"azure-core","optional":false},{"reason":"Required for creating and managing user access tokens for chat","package":"azure-communication-identity","optional":false}],"imports":[{"note":"","wrong":"","symbol":"ChatClient","correct":"from azure.communication.chat import ChatClient"},{"note":"AccessToken is used internally, but the correct class for chat is CommunicationTokenCredential","wrong":"from azure.core.credentials import AccessToken","symbol":"CommunicationTokenCredential","correct":"from azure.communication.chat import CommunicationTokenCredential"}],"quickstart":{"code":"import os\nfrom azure.communication.chat import ChatClient, CommunicationTokenCredential\n\nendpoint = os.environ.get(\"COMMUNICATION_SERVICES_ENDPOINT\", \"\")\nuser_access_token = os.environ.get(\"USER_ACCESS_TOKEN\", \"\")\n\ncredential = CommunicationTokenCredential(user_access_token)\nchat_client = ChatClient(endpoint, credential)\n\n# Create a chat thread\nfrom azure.communication.chat import CreateChatThreadRequest\n\ncreate_chat_thread_request = CreateChatThreadRequest(\n    topic=\"Hello World!\",\n    members=[\n        {\"user\": \"8:acs:...\", \"display_name\": \"User1\"},\n        {\"user\": \"8:acs:...\", \"display_name\": \"User2\"}\n    ]\n)\n\nresult = chat_client.create_chat_thread(create_chat_thread_request)\nprint(f\"Chat thread created with ID: {result.chat_thread.id}\")","lang":"python","description":"Creates a chat thread with two participants using an endpoint and user access token."},"warnings":[{"fix":"Use CommunicationTokenCredential with a valid user access token obtained from the Communication Identity API.","message":"ChatClient constructor requires a CommunicationTokenCredential, not an AzureKeyCredential or DefaultAzureCredential. Using the wrong credential type will raise a TypeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the endpoint string ends with a '/'.","message":"The endpoint URL must include the trailing forward slash (e.g., 'https://<resource>.communication.azure.com/'). Missing the slash will cause an InvalidURL error.","severity":"gotcha","affected_versions":"all"},{"fix":"Use azure.communication.chat.ChatParticipant objects with 'user', 'display_name', and 'share_history_time'.","message":"In 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.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Use the overloaded constructor that accepts a callable for token refresh: CommunicationTokenCredential(token_refresh_callback).","message":"The CommunicationTokenCredential does not auto-refresh tokens. For long-lived applications, implement token refresh logic and wrap it in a callback.","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 chat_client.get_chat_thread_client(thread_id) to obtain a ChatThreadClient instance.","cause":"In older versions (pre-1.1.0), ChatThreadClient was accessed differently. In 1.2.0+, ChatThreadClient is obtained via ChatClient.get_chat_thread_client().","error":"AttributeError: module 'azure.communication.chat' has no attribute 'ChatThreadClient'"},{"fix":"Create ChatParticipant objects: from azure.communication.chat import ChatParticipant; members = [ChatParticipant(user=..., display_name=...)]","cause":"Passing a plain Python list for 'members' in CreateChatThreadRequest instead of a list of ChatParticipant objects.","error":"TypeError: Object of type 'list' is not JSON serializable"},{"fix":"Ensure the endpoint ends with '/', e.g., 'https://myresource.communication.azure.com/'.","cause":"The endpoint URL is missing a trailing slash or is incorrectly formatted.","error":"HttpRequestError: (InvalidURL) Invalid URL"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}