Skip to main content

Microsoft Azure Communication SMS Client Library for Python

Project description

Build Status

Azure Communication SMS Package client library for Python

This package contains a Python SDK for Azure Communication Services for SMS. Read more about Azure Communication Services here

Source code | Package (Pypi) | API reference documentation | Product documentation

Getting started

Prerequisites

  • Python 2.7, or 3.5 or later is required to use this package.
  • A deployed Communication Services resource. You can use the Azure Portal or the Azure PowerShell to set it up.
  • You must have a phone number configured that is associated with an Azure subscription

Install the package

Install the Azure Communication SMS client library for Python with pip:

pip install azure-communication-sms

Key concepts

Azure Communication SMS package is used to do following:

  • Send SMS Messages

Examples

The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including:

Client Initialization

To initialize the SMS Client, the connection string can be used to instantiate. Alternatively, you can also use Active Directory authentication using DefaultAzureCredential.

from azure.communication.sms import SmsClient
from azure.identity import DefaultAzureCredential

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
sms_client = SmsClient.from_connection_string(connection_string)
# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have
# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.
endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT')
sms_client = SmsClient(endpoint, DefaultAzureCredential())

Sending SMS Messages

Once the client is initialized, the .send() method can be invoked:

from azure.communication.sms import SendSmsOptions

sms_responses = sms_client.send(
    from_phone_number=PhoneNumberIdentifier("<leased-phone-number>"),
    to_phone_numbers=["<to-phone-number-1>", "<to-phone-number-2>", "<to-phone-number-3>"],
    message="Hello World via SMS",
    enable_delivery_report=True, # optional property
    tag="custom-tag") # optional property
  • from_phone_number: An SMS enabled phone number associated with your communication service.
  • to_phone_numbers: The phone numbers you wish to send a message to.
  • message: The message that you want to send.
  • enable_delivery_report: An optional parameter that you can use to configure delivery reporting. This is useful for scenarios where you want to emit events when SMS messages are delivered.
  • tag: An optional parameter that you can use to configure custom tagging.

Troubleshooting

The Azure Communication Service Identity client will raise exceptions defined in Azure Core.

Next steps

More sample code

Please take a look at the samples directory for detailed examples of how to use this library to send an sms.

Provide Feedback

If you encounter any bugs or have suggestions, please file an issue in the Issues section of the project

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure-communication-sms-1.0.0b6.zip (55.4 kB view details)

Uploaded Source

Built Distribution

azure_communication_sms-1.0.0b6-py2.py3-none-any.whl (35.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file azure-communication-sms-1.0.0b6.zip.

File metadata

  • Download URL: azure-communication-sms-1.0.0b6.zip
  • Upload date:
  • Size: 55.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for azure-communication-sms-1.0.0b6.zip
Algorithm Hash digest
SHA256 5271434d5bd40408778fedb522849630bc7356c49a647587b30cba4b7e36d4a0
MD5 2b58bbed8db77ad71d3bf3deee923cd0
BLAKE2b-256 3382d8a256a567cf9296492f8c87d3025e72cea1afa56b9d4fd580df530de14f

See more details on using hashes here.

File details

Details for the file azure_communication_sms-1.0.0b6-py2.py3-none-any.whl.

File metadata

  • Download URL: azure_communication_sms-1.0.0b6-py2.py3-none-any.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for azure_communication_sms-1.0.0b6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 77d5da97ee7f27bc839129534bd9fdfeafca6083c01462e722d8d8b130297b81
MD5 9ad9bd55f99eb5617362c22ce5acb3a5
BLAKE2b-256 0ca4bd0633c3bb0fbad931598f7b221ae6ccf7ce11bbf705f98a53779236891e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page