azure.communication.sms package

class azure.communication.sms.SmsClient(endpoint: str, credential: TokenCredential, **kwargs: Any)[source]

A client to interact with the AzureCommunicationService Sms gateway.

This client provides operations to send an SMS via a phone number.

Parameters
  • endpoint (str) – The endpoint url for Azure Communication Service resource.

  • credential (TokenCredential) – The TokenCredential we use to authenticate against the service.

classmethod from_connection_string(conn_str: str, **kwargs: Any) → SmsClient[source]

Create SmsClient from a Connection String.

Parameters

conn_str (str) – A connection string to an Azure Communication Service resource.

Returns

Instance of SmsClient.

Return type

SmsClient

Example:

send(from_: str, to: Union[str, List[str]], message: str, **kwargs: Any)[SmsSendResult][source]

Sends SMSs to phone numbers.

Parameters
  • from (str) – The sender of the SMS.

  • to (Union[str, List[str]]) – The single recipient or the list of recipients of the SMS.

  • message (str) – The message in the SMS

Keyword Arguments
  • enable_delivery_report (bool) – Enable this flag to receive a delivery report for this message on the Azure Resource EventGrid.

  • tag (str) – Use this field to provide metadata that will then be sent back in the corresponding Delivery Report.

Returns

A list of SmsSendResult.

Return type

[SmsSendResult]

class azure.communication.sms.SmsSendResult(*, to: str, http_status_code: int, successful: bool, message_id: Optional[str] = None, error_message: Optional[str] = None, **kwargs)[source]

Response for a single recipient.

All required parameters must be populated in order to send to Azure.

Parameters
  • to (str) – Required. The recipient’s phone number in E.164 format.

  • message_id (str) – The identifier of the outgoing Sms message. Only present if message processed.

  • http_status_code (int) – Required. HTTP Status code.

  • successful (bool) – Required. Indicates if the message is processed successfully or not.

  • error_message (str) – Optional error message in case of 4xx/5xx/repeatable errors.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list