Registry / azure / azure-communication-identity

azure-communication-identity

JSON →
library1.5.0pypypi✓ verified 85d ago

The `azure-communication-identity` library provides client-side functionality for managing user identities and issuing access tokens for Azure Communication Services. It allows applications to create, delete, and manage users, and to generate tokens required for client-side authentication with various communication functionalities like chat and calling. The current version is 1.5.0, and new versions are released regularly as part of the broader Azure SDK for Python, typically every 1-2 months or as features/fixes dictate.

pip install azure-communication-identity
INSTALL
IMPORT
SIG · AZURE-COMMUNICATIO
A
azure-communication-identity
azurepythonv1.5.0
Install
2.6s avg
Import
426ms
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.5.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.910 runs
installs and imports cleanly · install 0.0s · import 0.447s · 26.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.6s · import 0.405s · 27MB
25MB installed
● package 25MB
Code
Verified usage

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

CommunicationIdentityClient
from azure.communication.identity import CommunicationIdentityClient
CommunicationTokenScope
from azure.communication.identity.models import CommunicationTokenScope
from azure.communication.identity import CommunicationTokenScope
Starting from version 1.4.0, CommunicationTokenScope was moved to the `models` submodule.

This quickstart demonstrates how to initialize the `CommunicationIdentityClient`, create a new user identity, and issue an access token for that identity with specific scopes (e.g., chat and VoIP). It requires the `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable to be set, containing your Azure Communication Services resource's endpoint and access key. Identities incur costs, so consider deleting them after use if they are temporary.

import os from azure.communication.identity import CommunicationIdentityClient from azure.communication.identity.models import CommunicationTokenScope # Set the COMMUNICATION_SERVICES_CONNECTION_STRING environment variable # Example: 'endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>' connection_string = os.environ.get( "COMMUNICATION_SERVICES_CONNECTION_STRING", "endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>" ) if "endpoint=" not in connection_string or "accesskey=" not in connection_string: print("Error: COMMUNICATION_SERVICES_CONNECTION_STRING not set or invalid.") print("Please ensure it contains 'endpoint=' and 'accesskey='.") exit(1) try: client = CommunicationIdentityClient.from_connection_string(connection_string) print("CommunicationIdentityClient initialized.") # Create a new identity user = client.create_user() print(f"Created identity with ID: {user.communication_user_id}") # Issue an access token for the identity token_response = client.get_token( user, scopes=[CommunicationTokenScope.CHAT, CommunicationTokenScope.VOIP] ) print(f"Issued token (partial): {token_response.token[:10]}...{token_response.token[-10:]}") print(f"Token expires on: {token_response.expires_on}") # Clean up: Delete the created identity (optional, but good for cost management) # client.delete_user(user) # print(f"Deleted identity: {user.communication_user_id}") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingThe client class name changed from `CommunicationUserTokenClient` (in preview versions) to `CommunicationIdentityClient`.
fix
Update your code to use `from azure.communication.identity import CommunicationIdentityClient` and instantiate this class.
affects: <1.0.0
breakingThe method for issuing tokens was renamed from `issue_token` to `get_token`.
fix
Replace calls to `client.issue_token(...)` with `client.get_token(...)`.
affects: >=1.3.0
breakingThe `CommunicationTokenScope` enum moved from the main package namespace to the `models` submodule.
fix
Update your import statement from `from azure.communication.identity import CommunicationTokenScope` to `from azure.communication.identity.models import CommunicationTokenScope`.
affects: >=1.4.0
gotchaAzure Communication Service identities incur costs. Ensure you delete identities when they are no longer needed to avoid unexpected charges.
fix
Implement proper lifecycle management, including calling `client.delete_user(user)` when an identity is no longer required.
affects: All
gotchaThe connection string format must be exact: `endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>`. Missing parts or incorrect delimiters will lead to authentication errors.
fix
Verify the connection string obtained from the Azure portal, ensuring both 'endpoint=' and 'accesskey=' components are present and correctly formatted.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.communication.identity'
The package `azure-communication-identity` is not installed in your Python environment.
fix
Run: `pip install azure-communication-identity`
AttributeError: 'CommunicationIdentityClient' object has no attribute 'issue_token'
The method `issue_token` was renamed to `get_token` in version 1.3.0.
fix
Update your code to use `client.get_token(user, scopes=[...])` instead of `client.issue_token(...)`.
ValueError: Connection string is not in valid format.
The provided connection string is malformed or missing required components like 'endpoint' or 'accesskey'.
fix
Double-check your `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable or hardcoded string against the format `endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>`.
ImportError: cannot import name 'CommunicationTokenScope' from 'azure.communication.identity'
Starting from version 1.4.0, `CommunicationTokenScope` was moved to the `models` submodule.
fix
Change your import statement to `from azure.communication.identity.models import CommunicationTokenScope`.
Upgrade
Version history
1.5.0latest on PyPI · released Feb 15, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
24
OpenAI (training)
1
Resources
azure-communication-identity — pip install azure-communication-identity · libregistry