The Azure Communication SMS client library for Python allows developers to integrate SMS messaging capabilities into their applications. It provides functionalities to send 1:1 and 1:N SMS messages via Azure Communication Services. The library is currently at version 1.1.0 and is part of the Azure SDK for Python, which typically sees regular updates, including new features and bug fixes, often on a monthly or bi-monthly cadence, alongside public preview releases for upcoming functionalities.
pip install azure-communication-smsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `SmsClient` using a connection string and send a single SMS message. It is crucial to replace placeholder environment variables with your actual Azure Communication Services connection string, and SMS-enabled phone numbers in E.164 format. The `enable_delivery_report` flag is set to `True` to allow tracking message delivery status.
Ensure all phone numbers adhere strictly to the E.164 format, including the '+' prefix.
Verify SMS enablement and phone number status in the Azure Portal under your Communication Services resource. For toll-free numbers, ensure verification is complete.
Implement retry logic with exponential backoff, send messages in batches, monitor ACS quotas, and validate phone numbers before sending to reduce delivery failures.
Double-check the connection string for accuracy, ensure required AAD environment variables (AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET) are set if using `DefaultAzureCredential`, and verify that the principal has the 'Azure Communication Services Contributor' role or equivalent permissions.
Verify that the `AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING` environment variable is correctly set and matches your Communication Services resource. If using AAD, ensure `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, and `AZURE_CLIENT_SECRET` are correct and the service principal has the 'Azure Communication Services Contributor' role.
Grant the appropriate permissions, such as 'Azure Communication Services Contributor', to the identity being used for authentication on your Azure Communication Services resource.
Ensure all phone numbers are in E.164 format (e.g., `+14255550123`). Trim and normalize all input strings to remove any invisible or non-printable characters.
Review best practices: implement retry logic with exponential backoff, send messages in batches, monitor ACS quotas, and ensure `from_` and `to` numbers are valid, mobile, and SMS-capable. Check if the recipient has opted out.