{"templateId":"markdown","versions":[{"version":"1.0","label":"1.0","link":"/docs/sdks/python/1.0","default":false,"active":false,"folderId":"4340cde4"},{"version":"2.0","label":"2.0","link":"/docs/sdks/python","default":true,"active":true,"folderId":"4340cde4"}],"sharedDataIds":{"sidebar":"sidebar-docs/sdks/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial","admonition","tabs","tab","cards","card"]},"type":"markdown"},"seo":{"title":"Python SDK | Sinch","siteUrl":"https://developers.sinch.com","llmstxt":{"title":"Sinch Developer Documentation","description":"LLMs.txt containing a map of all the documentation files for Sinch.","sections":[{"title":"SMS API","description":"The SMS API allows you to send and receive SMS messages with a few easy steps. You can also send bulk SMS messages to multiple customers using the Sinch SMS service.","includeFiles":["docs/sms/**/*.md","docs/sms/**/*.yaml"],"excludeFiles":["docs/sms/index.md"]},{"title":"Numbers API","description":"The Numbers API enables you to search for, view, and activate numbers. It's considered a precursor to other APIs in the Sinch product family. The numbers API can be used in tandem with any of our APIs that perform messaging or calling.","includeFiles":["docs/numbers/**/*.md","docs/numbers/**/*.yaml"],"excludeFiles":["docs/numbers/index.md"]},{"title":"Conversation API","description":"Send and receive messages globally on many popular channels with ease and confidence when using Sinch's Conversation API. Conversation API is the preferred API for sending mobile messages on SMS and other social channels with Sinch. It is a simple API with unified error messages, consistent request payloads, and common webhook payloads that are channel-agnostic.","includeFiles":["docs/conversation/**/*.md","docs/conversation/**/*.yaml"],"excludeFiles":["docs/conversation/index.md"]},{"title":"Voice API","description":"The Voice API works as a big telephony switch. The Voice API handles incoming phone calls (also known as incoming call “legs”), sets up outgoing phone calls (or outgoing call “legs”), and bridges the two. The incoming call leg may come in over a data connection (from a smartphone or web application using the Sinch SDKs) or through a local phone number (from the PSTN network). Similarly, the outgoing call leg can be over data (to another smartphone or web application using the Sinch SDKs) or the PSTN network.","includeFiles":["docs/voice/**/*.md","docs/voice/**/*.yaml"],"excludeFiles":["docs/voice/index.md"]},{"title":"Verification API","description":"The Verification API is a platform for phone number verification. It consists of the API and different software development kits (the Sinch SDKs) that you integrate with your smartphone or web application and cloud based back-end services. Together they enable SMS, Flashcall, Phone Call and Data verification in your application.","includeFiles":["docs/verification/**/*.md","docs/verification/**/*.yaml"],"excludeFiles":["docs/verification/index.md"]},{"title":"Provisioning API","description":"Provisioning API allows you to programmatically set up your senders, accounts and templates on your favorite messaging platforms on the Conversation API. For now, you can create your first WhatsApp channel through Meta's Embedded sign up, you can configure your first SMS App and configure your webhooks. As development continues, we will be adding the most commonly used channels.","includeFiles":["docs/provisioning-api/**/*.md","docs/provisioning-api/**/*.json"],"excludeFiles":["docs/provisioning-api/index.md"]},{"title":"Elastic SIP Trunking API","description":"With Elastic SIP Trunking you can create and manage your SIP trunks and phone numbers programmatically.","includeFiles":["docs/est/**/*.md","docs/est/**/*.yaml"],"excludeFiles":["docs/est/index.md"]},{"title":"Fax API","description":"Send and receive HIPAA compliant faxes on our modern fax platform using our developer-friendly API.","includeFiles":["docs/fax/**/*.md","docs/fax/**/*.yaml"],"excludeFiles":["docs/fax/index.md"]},{"title":"In-app Voice and Video SDK","description":"The In-app Voice and Video SDK enables you to add voice and video calling capabilities directly into your mobile or web application using the Sinch SDKs.","includeFiles":["docs/in-app-calling/**/*.md"],"excludeFiles":["docs/in-app-calling/index.md"]}],"hide":false,"excludeFiles":[]},"description":"Read all about the Sinch Python SDK."},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"python-sdk","__idx":0},"children":["Python SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Python SDK allows you to quickly interact with the ","suite of Sinch APIs"," from inside your Python applications. When using the Python SDK, the code representing requests and queries sent to and responses received from the ","suite of Sinch APIs"," are structured similarly to those that are sent and received using the ","suite of Sinch APIs","."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Important Python SDK links:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following links are available for your reference:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/sinch/sinch-sdk-python"},"children":["Sinch Python SDK repository"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/sinch/sinch-sdk-python/releases"},"children":["Sinch Python SDK releases"]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"client","__idx":1},"children":["Client"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When using the Sinch Python SDK, you initialize communication with the Sinch backend by initializing the Python SDK's main client class. This client allows you to access the functionality of the Sinch Python SDK."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"initialization","__idx":2},"children":["Initialization"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To start using the SDK, you need to initialize the main client class with your credentials from your Sinch ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://dashboard.sinch.com"},"children":["dashboard"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from sinch import SinchClient\n\nsinch_client = SinchClient(key_id=\"key_id\", key_secret=\"key_secret\", project_id=\"YOUR_project_id\")\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials, as in the following example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import os\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(\n    key_id=os.getenv(\"KEY_ID\"),\n    key_secret=os.getenv(\"KEY_SECRET\"),\n    project_id=os.getenv(\"PROJECT_ID\")\n)\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"sms-api","__idx":3},"children":["SMS API"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For the SMS API in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Australia (AU)"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Brazil (BR)"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Canada (CA)"]},", ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["the United States (US)"]},","," ","and ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["the European Union (EU)"]},",  provide the following parameters:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from sinch import SinchClient\n\nsinch_client = SinchClient(\n    service_plan_id=\"service_plan_id\",\n    sms_api_token=\"api_token\"\n)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"Setting the region"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You must set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms_region"]}," before using the SMS API and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation_region"]}," before using the Conversation API, either in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["SinchClient(...)"]}," constructor or on ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch_client.configuration"]}," before the first call to that product, as in the following examples:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Conversation","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from sinch import SinchClient\n\nsinch_client = SinchClient(\n    project_id=\"your-project-id\",\n    key_id=\"your-key-id\",\n    key_secret=\"your-key-secret\",\n    conversation_region=\"eu\",\n)\n\n# Note: The conversation_region can also be set through the configuration object,\n# but you must ensure this setting is done BEFORE any Conversation API call:\nsinch_client.configuration.conversation_region = \"eu\"\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"SMS","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from sinch import SinchClient\n\n# Using Project auth\nsinch_client = SinchClient(\n    project_id=\"your-project-id\",\n    key_id=\"your-key-id\",\n    key_secret=\"your-key-secret\",\n    sms_region=\"eu\",\n)\n\n# Or using SMS token auth\ntoken_client = SinchClient(\n    service_plan_id=\"your-service-plan-id\",\n    sms_api_token=\"your-sms-api-token\",\n    sms_region=\"us\",\n)\n\n# Note: The code is backward compatible. The sms_region can still be set through the configuration object,\n# but you must ensure this setting is done BEFORE any SMS API call:\nsinch_client.configuration.sms_region = \"eu\"\n","lang":"python"},"children":[]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"domains","__idx":4},"children":["Domains"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Python SDK currently supports the following products:"]},{"$$mdtype":"Tag","name":"Cards","attributes":{"columns":4,"cardMinWidth":100},"children":[{"$$mdtype":"Tag","name":"Card","attributes":{"title":"Numbers","icon":"/assets/python.b048095ba600cf4f71c73b097ca8e466d4b1a2f8cf00c2a778f2b241619362e8.83be2fd5.png","imagePosition":"start","iconPosition":"auto","layout":"horizontal","align":"start","variant":"filled","to":"#numbers-domain"},"children":[]},{"$$mdtype":"Tag","name":"Card","attributes":{"title":"Number Lookup","icon":"/assets/python.b048095ba600cf4f71c73b097ca8e466d4b1a2f8cf00c2a778f2b241619362e8.83be2fd5.png","imagePosition":"start","iconPosition":"auto","layout":"horizontal","align":"start","variant":"filled","to":"#number-lookup-domain"},"children":[]},{"$$mdtype":"Tag","name":"Card","attributes":{"title":"SMS","icon":"/assets/python.b048095ba600cf4f71c73b097ca8e466d4b1a2f8cf00c2a778f2b241619362e8.83be2fd5.png","imagePosition":"start","iconPosition":"auto","layout":"horizontal","align":"start","variant":"filled","to":"#sms-domain"},"children":[]},{"$$mdtype":"Tag","name":"Card","attributes":{"title":"Conversation","icon":"/assets/python.b048095ba600cf4f71c73b097ca8e466d4b1a2f8cf00c2a778f2b241619362e8.83be2fd5.png","imagePosition":"start","iconPosition":"auto","layout":"horizontal","align":"start","variant":"filled","to":"#conversation-domain"},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"numbers-domain","__idx":5},"children":["Numbers Domain"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide describes the syntactical structure of the Python SDK for the Numbers API, including any differences that may exist between the API itself and the SDK. For a full reference on Numbers API calls and responses, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers"},"children":["Numbers API Reference"]},"."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The code sample on this page is an example of how to use the Python SDK to list the available numbers given a set of constraints. We've also provided an example that accomplishes the same task using the REST API."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/code-snippets/python_sdk/numbers/list-numbers.sample.py","language":"python","title":"list_numbers.py","header":{"title":"list_numbers.py","controls":{"copy":{}}},"lang":"python","source":"\"\"\"\nSinch Python Snippet\n\nThis snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets\n\"\"\"\n\nimport os\nfrom dotenv import load_dotenv\nfrom sinch import SinchClient\n\nload_dotenv()\n\nsinch_client = SinchClient(\n    project_id=os.environ.get(\"SINCH_PROJECT_ID\") or \"MY_PROJECT_ID\",\n    key_id=os.environ.get(\"SINCH_KEY_ID\") or \"MY_KEY_ID\",\n    key_secret=os.environ.get(\"SINCH_KEY_SECRET\") or \"MY_KEY_SECRET\"\n)\n\navailable_numbers = sinch_client.numbers.search_for_available_numbers(\n    region_code=\"AR\",\n    number_type=\"LOCAL\"\n)\n\nprint(\"Available numbers to rent:\\n\")\nfor number in available_numbers.iterator():\n    print(number)\n"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Json","header":{"controls":{"copy":{}}},"source":"\nimport requests\n\nproject_id = \"YOUR_project_id\"\nurl = \"https://numbers.api.sinch.com/v1/projects/\" + project_id + \"/availableNumbers\"\n\nquery = {\n  \"regionCode\": \"US\",\n  \"type\": \"LOCAL\"\n}\n\nresponse = requests.get(url, params=query, auth=('<username>','<password>'))\n\ndata = response.json()\nprint(data)\n\n","lang":"Json"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Python SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch_client.numbers.[endpoint_category].[method]"]},". You can also create a domain-specific client from a general client. For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(key_id=\"YOUR_key_id\", key_secret=\"YOUR_key_secret\",\nproject_id=\"YOUR_project_id\")\n\nfrom sinch.domains.numbers import Numbers\n\nnumbers_client = Numbers(sinch_client)\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"endpoint-categories","__idx":6},"children":["Endpoint categories"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the Sinch Python SDK, Numbers API endpoints are accessible through the client (either a general client or a Numbers-specific client)."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers.regions"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers.event_destinations"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nnumbers_available = sinch_client.numbers.search_for_available_numbers(\n    region_code=\"US\",\n    number_type=\"LOCAL\"\n)\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"numbers-endpoint-category","__idx":7},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/available-number/"},"children":["available-numbers"]}," and ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/active-number/"},"children":["active-numbers"]}," endpoints. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/available-number/numberservice_rentanynumber"},"children":["Rent the first available number matching the provided criteria"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["rent_any"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/available-number/numberservice_rentnumber"},"children":["Activate a new phone number"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["rent"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/available-number/numberservice_getavailablenumber"},"children":["Check availability"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["check_availability"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/available-number/numberservice_listavailablenumbers"},"children":["Search for available phone numbers"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["search_for_available_numbers"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/active-number/numberservice_listactivenumbers"},"children":["List active numbers for a project"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["list"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/active-number/numberservice_updateactivenumber"},"children":["Update active number"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/active-number/numberservice_getactivenumber"},"children":["Retrieve active number"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/active-number/numberservice_releasenumber"},"children":["Release active number"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["release"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"numbersregions-endpoint-category","__idx":8},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers.regions"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers.regions"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/available-regions/"},"children":["available-regions"]}," endpoint. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/available-regions/"},"children":["List available regions"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["list"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"event_destinations-endpoint-category","__idx":9},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["event_destinations"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numbers.event_destinations"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/numbers-callbacks"},"children":["numbers-callbacks"]}," endpoint. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/numbers-callbacks/getcallbackconfiguration"},"children":["Get callbacks configuration"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/numbers/api-reference/numbers/numbers-callbacks/updatecallbackconfiguration"},"children":["Update callbacks configuration"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"request-and-query-parameters","__idx":10},"children":["Request and query parameters"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Requests and queries made using the Python SDK are similar to those made using the Numbers API. Many of the fields are named and structured similarly. For example, consider the representations of a Numbers API region code. One field is represented in JSON, and the other is using our Python SDK:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"region_code = \"US\"\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\"regionCode\": \"US\"\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that the fields are nearly the same. Additionally, path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding Python method."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"field-name-differences","__idx":11},"children":["Field name differences"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When translating field names from the Numbers API to the Python SDK, remember that many of the API field names are in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["camelCase"]},", whereas the Python SDK field names are in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["snake_case"]},". This pattern change manages almost all field name translations between the API and the SDK."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Below is a table detailing field names present in the Numbers API and their modified counterparts in the Numbers API Python SDK:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API field name"},"children":["API field name"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK field name"},"children":["SDK field name"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["regionCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["region_code"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_type"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["types"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_types"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numberPattern.pattern"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_pattern"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["numberPattern.searchPattern"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_search_pattern"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["phoneNumber"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["phone_number"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["smsConfiguration"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms_configuration"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["capability"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["capabilities"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"nested-objects","__idx":12},"children":["Nested objects"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When making calls directly to the API, we use JSON objects, including (in some cases) nested JSON objects. When using the Python SDK, we use dictionaries instead of nested JSON objects. For example, consider the sms configuration objects below. One is represented in JSON, the other as a Python dictionary:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"sms_configuration = {\n    \"servicePlanId\": \"service_plan_string\"\n}\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"{","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\"smsConfiguration\": {\n    \"servicePlanId\": \"service_plan_string\"\n}\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that, in both cases, the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["servicePlanId"]}," object is structured in exactly the same way as they would be in a normal Python call to the Numbers API. When using the Python SDK, any argument that represents a nested JSON object will be represented as a Python dictionary at the top level, but the contents of that dictionary must be represented as JSON objects."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"responses","__idx":13},"children":["Responses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Response fields match the API responses. They are delivered as Python objects, with each top-level field represented as a property. Note that any nested objects normally returned by the Numbers API are returned as dictionaries by the Python SDK. Additionally, if there are any responses that differ significantly from the API responses, we note them in the endpoint category documentation."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"number-lookup-domain","__idx":14},"children":["Number Lookup Domain"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide describes the syntactical structure of the Python SDK for the Number Lookup API, including any differences that may exist between the API itself and the SDK. For a full reference on Number Lookup API calls and responses, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/number-lookup-api-v2/api-reference/number-lookup-v2"},"children":["Number Lookup API Reference"]},"."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The code sample on this page is an example of how to use the Python SDK to look up a phone number. We've also provided an example that accomplishes the same task using the REST API."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/code-snippets/python_sdk/number-lookup/lookup-number.sample.py","language":"python","title":"snippet.py","header":{"title":"snippet.py","controls":{"copy":{}}},"lang":"python","source":"\"\"\"\nSinch Python Snippet\n\nThis snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets\n\"\"\"\n\nimport os\nfrom dotenv import load_dotenv\nfrom sinch import SinchClient\n\nload_dotenv()\n\nsinch_client = SinchClient(\n    project_id=os.environ.get(\"SINCH_PROJECT_ID\") or \"MY_PROJECT_ID\",\n    key_id=os.environ.get(\"SINCH_KEY_ID\") or \"MY_KEY_ID\",\n    key_secret=os.environ.get(\"SINCH_KEY_SECRET\") or \"MY_KEY_SECRET\",\n)\n\n# The phone number to look up in E.164 format (e.g. +1234567890)\nphone_number = \"PHONE_NUMBER\"\n\nresponse = sinch_client.number_lookup.lookup(number=phone_number)\n\nprint(f\"Number lookup result:\\n{response}\")\n"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Json","header":{"controls":{"copy":{}}},"source":"\nimport requests\n\nkey = \"YOUR_access_key\"\nsecret = \"YOUR_access_secret\"\nproject_id = \"YOUR_project_id\"\nnumber = \"YOUR_phone_number\"\nurl = \"https://lookup.api.sinch.com/v2/projects/\" + project_id + \"/lookups\"\n\ndef lookup(num):\n    payload = {\n        \"number\": num\n    }\n\n    headers = {\n        \"Content-Type\": \"application/json\"\n    }\n\n    response = requests.post(url, json=payload, headers=headers, auth=(key, secret))\n\n    data = response.json()\n    print(data)\n\nlookup(number)\n\n","lang":"Json"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Python SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch_client.number_lookup.[endpoint_category].[method]"]},". You can also create a domain-specific client from a general client. For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(key_id=\"YOUR_key_id\", key_secret=\"YOUR_key_secret\",\nproject_id=\"YOUR_project_id\")\n\nfrom sinch.domains.number_lookup import NumberLookup\n\nnumber_lookup_client = NumberLookup(sinch_client)\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"endpoint-categories-1","__idx":15},"children":["Endpoint categories"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the Sinch Python SDK, Number Lookup API endpoints are accessible through the client (either a general client or a Number Lookup-specific client). The naming convention of the endpoint's representation in the SDK matches the API:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nlookup_number = sinch_client.number_lookup.lookup(number=\"YOUR_PHONE_NUMBER\")\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"lookup-endpoint-category","__idx":16},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/number-lookup-api-v2/api-reference/number-lookup-v2/numberlookupv2/"},"children":["lookup"]}," endpoint. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/number-lookup-api-v2/api-reference/number-lookup-v2/numberlookupv2/numberlookupv2_lookup"},"children":["Look up a phone number"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lookup"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"request-and-query-parameters-1","__idx":17},"children":["Request and query parameters"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Requests and queries made using the Python SDK are similar to those made using the Number Lookup API. Many of the fields are named and structured similarly. For example, consider the representations of a Number Lookup API region code. One field is represented in JSON, and the other is using our Python SDK:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"mobile_country_code = \"310\"\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\"mobileCountryCode\": \"310\"\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that the fields are nearly the same. Additionally, path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding Python method."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"field-name-differences-1","__idx":18},"children":["Field name differences"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When translating field names from the Number Lookup API to the Python SDK, remember that many of the API field names are in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["camelCase"]},", whereas the Python SDK field names are in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["snake_case"]},". This pattern change manages almost all field name translations between the API and the SDK."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Below is a table detailing field names present in the Number Lookup API and their modified counterparts in the Number Lookup API Python SDK:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API field name"},"children":["API field name"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK field name"},"children":["SDK field name"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["regionCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["region_code"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_type"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["types"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number_types"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mobileCountryCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["mobile_country_code"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["swapPeriod"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["swap_period"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["phoneNumber"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["phone_number"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["portingDate"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["porting_date"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"responses-1","__idx":19},"children":["Responses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Response fields match the API responses. They are delivered as Python objects, with each top-level field represented as a property. Note that any nested objects normally returned by the Number Lookup API are returned as dictionaries by the Python SDK. Additionally, if there are any responses that differ significantly from the API responses, we note them in the endpoint category documentation."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"sms-domain","__idx":20},"children":["SMS Domain"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":" Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide describes the syntactical structure of the Python SDK for the SMS API, including any differences that may exist between the API itself and the SDK. For a full reference on SMS API calls and responses, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/"},"children":["SMS API Reference"]},"."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The code sample below is an example of how to use the Python SDK to send a text message using the SMS API. We've also provided an example that accomplishes the same task using the REST API."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/code-snippets/python_sdk/sms/send-message.sample.py","language":"python","title":"send-message.py","header":{"title":"send-message.py","controls":{"copy":{}}},"lang":"python","source":"\"\"\"\nSinch Python Snippet\n\nThis snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets\n\"\"\"\n\nimport os\nfrom dotenv import load_dotenv\nfrom sinch import SinchClient\n\nload_dotenv()\n\nsinch_client = SinchClient(\n    project_id=os.environ.get(\"SINCH_PROJECT_ID\") or \"MY_PROJECT_ID\",\n    key_id=os.environ.get(\"SINCH_KEY_ID\") or \"MY_KEY_ID\",\n    key_secret=os.environ.get(\"SINCH_KEY_SECRET\") or \"MY_KEY_SECRET\",\n    sms_region=os.environ.get(\"SINCH_SMS_REGION\") or \"MY_SMS_REGION\"\n)\n\nresponse = sinch_client.sms.batches.send_sms(\n    to=[\"+1234567890\"],\n    from_=\"+2345678901\",\n    body=\"Hello, this is a test message!\"\n)\n\nprint(f\"Batch sent:\\n{response}\")\n\n"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Json","header":{"controls":{"copy":{}}},"source":"\nimport requests\n\nservicePlanId = \"YOUR_service_plan_id\"\napiToken = \"YOUR_api_token\"\nsinchNumber = \"YOUR_Sinch_number\"\ntoNumber = \"YOUR_recipient_number\"\nurl = \"https://us.sms.api.sinch.com/xms/v1/\" + servicePlanId + \"/batches\"\n\npayload = {\n  \"from\": sinchNumber,\n  \"to\": [\n    toNumber\n  ],\n  \"body\": \"Hello from Sinch!\"\n}\n\nheaders = {\n  \"Content-Type\": \"application/json\",\n  \"Authorization\": \"Bearer \" + apiToken\n}\n\nresponse = requests.post(url, json=payload, headers=headers)\n\ndata = response.json()\nprint(data)\n\n","lang":"Json"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Python SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch_client.sms.[endpoint_category].[method]"]},". You can also create a domain-specific client from a general client. For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(key_id=\"YOUR_key_id\", key_secret=\"YOUR_key_secret\",\nproject_id=\"YOUR_project_id\")\n\nfrom sinch.domains.sms import SMS\n\nSMS_client = SMS(sinch_client)\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"endpoint-categories-2","__idx":21},"children":["Endpoint categories"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the Sinch Python SDK, SMS API endpoints are accessible through the client (either a general client or a SMS-specific client). The naming convention of the endpoint's representation in the SDK matches the API:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms.batches"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms.delivery_reports"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms.sinch_events"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"send_batch_response = sinch_client.sms.batches.send(\n    body = \"Hello from Sinch!\",\n    to = [\"YOUR_to_number\"],\n    from_ = \"YOUR_Sinch_number\",\n    delivery_report = \"none\"\n)\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"smsbatches-endpoint-category","__idx":22},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms.batches"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms.batches"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/"},"children":["batches"]}," endpoint. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/sendsms"},"children":["Send an SMS"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_sms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/sendsms"},"children":["Send an MMS"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_mms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/sendsms"},"children":["Send a binary message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_binary"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/listbatches"},"children":["List batches"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["list"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/dry_run"},"children":["Dry run an SMS"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["dry_run_sms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/dry_run"},"children":["Dry run an MMS"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["dry_run_mms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/dry_run"},"children":["Dry run a binary message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["dry_run_binary"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/getbatchmessage"},"children":["Get a batch message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/updatebatchmessage"},"children":["Update a batch SMS"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update_sms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/updatebatchmessage"},"children":["Update a batch MMS"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update_mms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/updatebatchmessage"},"children":["Update a batch binary message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update_binary"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/replacebatch"},"children":["Replace an SMS batch"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["replace_sms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/replacebatch"},"children":["Replace an MMS batch"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["replace_mms"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/replacebatch"},"children":["Replace a binary batch"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["replace_binary"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/cancelbatchmessage"},"children":["Cancel a batch message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["cancel"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/batches/deliveryfeedback"},"children":["Send delivery feedback for a message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_delivery_feedback"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"delivery_reports-endpoint-category","__idx":23},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["delivery_reports"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["delivery_reports"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/delivery-reports/"},"children":["delivery_report and delivery_reports"]}," endpoints. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/delivery-reports/getdeliveryreportbybatchid"},"children":["Retrieve a delivery report"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/delivery-reports/getdeliveryreportbyphonenumber"},"children":["Retrieve a recipient delivery report"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get_for_number"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/sms/api-reference/sms/delivery-reports/getdeliveryreports"},"children":["Retrieve a list of delivery reports"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["list"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"smssinch_events-endpoint-category","__idx":24},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms.sinch_events"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sms.sinch_events"]}," category of the Python SDK contains methods for webhook signature validation."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Validate signature"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_validate_signature"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Validate authentication header"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["validate_authentication_header"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Parse event"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["parse_event"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"request-and-query-parameters-2","__idx":25},"children":["Request and query parameters"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["service_plan_id"]}," path parameter does not need to be included in any requests created by the Python SDK."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Requests and queries made using the Python SDK are similar to those made using the SMS API. Many of the fields are named and structured similarly. In most cases, they are the same. For example, consider the representations of a SMS API app ID below. One field is represented in JSON, and the other is using our Python SDK:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"batch_id = \"{BATCH_ID}\"\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\"batch_id\": \"{BATCH_ID}\"\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that the fields have the same name. Additionally, path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding python method. For example, consider this example in which the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}," method of the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["batch"]}," class is invoked:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nSMS_response = sinch_client.sms.batches.get(\"01GR4H81QVX78E06F8ETGQ1CZK\")\n\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\nurl = \"https://us.SMS.api.sinch.com/v1/\" + service_plan_id + \"/batches/\" + batch_id\n\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When using the SMS API, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["service_plan_id"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["batch_id"]}," would be included as path parameters in the JSON payload. With the Python SDK, the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["batch_id"]}," parameter is included as an argument in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}," method."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"field-name-differences-2","__idx":26},"children":["Field name differences"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Below is a table detailing field names present in the SMS API and their modified counterparts in the SMS API Python SDK:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API field name"},"children":["API field name"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK field name"},"children":["SDK field name"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["type_"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["from"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["from_"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["recipient_msisdn"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["recipient_number"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"nested-objects-1","__idx":27},"children":["Nested objects"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When making calls directly to the API, we use JSON objects, including (in some cases) nested JSON objects. When using the Python SDK, we use dictionaries instead of nested JSON objects."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"responses-2","__idx":28},"children":["Responses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Response fields match the API responses. They are delivered as Python objects, with each top-level field represented as a property. Note that any nested objects normally returned by the SMS API are returned as dictionaries by the Python SDK."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Any field labelled ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["from"]}," in the API is labelled as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["from_"]}," in the Python SDK."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"conversation-domain","__idx":29},"children":["Conversation Domain"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":" Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide describes the syntactical structure of the Python SDK for the Conversation API, including any differences that may exist between the API itself and the SDK. For a full reference on Conversation API calls and responses, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation"},"children":["Conversation API Reference"]},"."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The code sample below is an example of how to use the Python SDK to send a text message on the SMS channel of a Conversation API app. The Conversation API call that accomplishes the same task is displayed below for reference."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/code-snippets/python_sdk/conversation/send-message.sample.py","language":"python","title":"send-message.py","header":{"title":"send-message.py","controls":{"copy":{}}},"lang":"python","source":"\"\"\"\nSinch Python Snippet\n\nThis snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets\n\"\"\"\n\nimport os\nfrom dotenv import load_dotenv\nfrom sinch import SinchClient\n\nload_dotenv()\n\nsinch_client = SinchClient(\n    project_id=os.environ.get(\"SINCH_PROJECT_ID\") or \"MY_PROJECT_ID\",\n    key_id=os.environ.get(\"SINCH_KEY_ID\") or \"MY_KEY_ID\",\n    key_secret=os.environ.get(\"SINCH_KEY_SECRET\") or \"MY_KEY_SECRET\",\n    conversation_region=os.environ.get(\"SINCH_CONVERSATION_REGION\") or \"MY_CONVERSATION_REGION\"\n)\n\n# The ID of the Conversation App to send the message from\napp_id = \"CONVERSATION_APP_ID\"\n# The phone number of the recipient in E.164 format (e.g. +46701234567)\nrecipient_identities = [\n    {\n        \"channel\": \"SMS\",\n        \"identity\": \"RECIPIENT_PHONE_NUMBER\"\n    }\n]\n\nresponse = sinch_client.conversation.messages.send_text_message(\n    app_id=app_id,\n    text=\"[Python SDK: Conversation] Sample text message\",\n    recipient_identities=recipient_identities\n)\n\nprint(f\"Successfully sent text message.\\n{response}\")\n"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Json","header":{"controls":{"copy":{}}},"source":"\nimport requests\nimport base64\n\nappId = \"YOUR_app_id\"\naccessKey = \"YOUR_key_id\"\naccessSecret = \"YOUR_key_secret\"\nprojectId = \"YOUR_project_id\"\nchannel = \"SMS\"\nidentity = \"RECIPIENT_number\"\nsender = \"YOUR_sms_sender\"\nurl = \"https://us.conversation.api.sinch.com/v1/projects/\" + projectId + \"/messages:send\"\n\ndata = accessKey + \":\" + accessSecret\nencodedBytes = base64.b64encode(data.encode(\"utf-8\"))\naccessToken = str(encodedBytes, \"utf-8\")\n\npayload = {\n  \"app_id\": appId,\n  \"recipient\": {\n      \"identified_by\": {\n          \"channel_identities\": [\n            {\n                \"channel\": channel,\n                \"identity\": identity\n            }  \n            ]\n      }\n  },\n  \"message\": {\n      \"text_message\": {\n          \"text\": \"Text message from Sinch Conversation API.\"\n      }\n  },\n  \"channel_properties\": {\n    \"SMS_SENDER\": sender\n  }  \n}\n\nheaders = {\n  \"Content-Type\": \"application/json\",\n  \"Authorization\": \"Basic \" + accessToken\n}\n\nresponse = requests.post(url, json=payload, headers=headers)\n\ndata = response.json()\nprint(data)\n\n","lang":"Json"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Python SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch_client.conversation.[endpoint_category].[method]"]},". You can also create a domain-specific client from a general client. For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(key_id=\"YOUR_key_id\", key_secret=\"YOUR_key_secret\",\nproject_id=\"YOUR_project_id\")\n\nfrom sinch.domains.conversation import Conversation\n\nconversation_client = Conversation(sinch_client)\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"endpoint-categories-3","__idx":30},"children":["Endpoint categories"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the Sinch Python SDK, Conversation API endpoints are accessible through the client (either a general client or a Conversation-specific client). The naming convention of the endpoint's representation in the SDK matches the API:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation.messages"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation.sinch_events"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\napp_id = \"CONVERSATION_APP_ID\"\nrecipient_identities = [\n    {\n        \"channel\": \"SMS\",\n        \"identity\": \"RECIPIENT_PHONE_NUMBER\"\n    }\n]\n\nresponse = sinch_client.conversation.messages.send_text_message(\n    app_id=app_id,\n    text=\"[Python SDK: Conversation] Sample text message\",\n    recipient_identities=recipient_identities\n)\n\n","lang":"Python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"conversationmessages-endpoint-category","__idx":31},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation.messages"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation.messages"]}," category of the Python SDK corresponds to the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation/messages/"},"children":["messages"]}," endpoint. The mapping between the API operations and corresponding Python methods are described below:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation/messages/messages_sendmessage"},"children":["Send a message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation/messages/messages_getmessage"},"children":["Get a message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation/messages/messages_deletemessage"},"children":["Delete a message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["delete"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation/messages/messages_listmessages"},"children":["List messages"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["list"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation/messages/messages_updatemessagemetadata"},"children":["Update message metadata"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/api-reference/conversation/messages/messages_listmessagesbychannelidentity"},"children":["List messages by channel identity"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["list_last_messages_by_channel_identity"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Additionally, there are several helper methods for sending messages of the different media types:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a card message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_card_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a carousel message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_carousel_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a choice message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_choice_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a contact info message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_contact_info_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a list message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_list_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a location message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_location_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a media message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_media_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a template message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_template_message"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developers.sinch.com/docs/conversation/api-reference/conversation/messages/messages_sendmessage#messages/messages_sendmessage/t=request&path=message"},"children":["Send a text message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send_text_message"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"conversationsinch_events-endpoint-category","__idx":32},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation.sinch_events"]}," endpoint category"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation.sinch_events"]}," category of the Python SDK contains methods for webhook signature validation."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API operation"},"children":["API operation"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK method"},"children":["SDK method"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Validate signature"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_validate_signature"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Validate authentication header"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["validate_authentication_header"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Parse event"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["parse_event"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"request-and-query-parameters-3","__idx":33},"children":["Request and query parameters"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Requests and queries made using the Python SDK are similar to those made using the Conversation API. Many of the fields are named and structured similarly. In most cases, they are the same. For example, consider the representations of a Conversation API app ID below. One field is represented in JSON, and the other is using our Python SDK:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"app_id = \"{APP_ID}\"\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\"app_id\": \"{APP_ID}\"\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that the fields have the same name. Additionally, path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding python method. For example, consider this example in which the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}," method of the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["message"]}," class is invoked:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nconversation_response = sinch_client.conversation.messages.get(\n                    message_id=\"YOUR_message_id\"\n                    messages_source=\"CONVERSATION_SOURCE\")\n\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\nurl = \"https://us.conversation.api.sinch.com/v1/projects/\" + project_id + \"/messages/\" + YOUR_message_id\n\npayload = {\n    \"messages_source\": \"CONVERSATION_SOURCE\"\n}\n\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When using the Conversation API, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["message_id"]}," would be included as a path parameter, and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["messages_source"]}," would be included as a query parameter in the JSON payload. With the Python SDK, both parameters are included as arguments in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get"]}," method."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"field-name-differences-3","__idx":34},"children":["Field name differences"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Below is a table detailing field names present in the Conversation API and their modified counterparts in the Conversation API Python SDK:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"API field name"},"children":["API field name"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"SDK field name"},"children":["SDK field name"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["metadata_json"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation_metadata"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update_mask.paths"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["update_mask"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["message.conversation_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversation_id"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["from"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["from_"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["default_translation"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["default_translations"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["template.id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["template_id"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"nested-objects-2","__idx":35},"children":["Nested objects"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When making calls directly to the API, we use JSON objects, including (in some cases) nested JSON objects. When using the Python SDK, we use dictionaries instead of nested JSON objects. For example, consider the message objects below. One is represented in JSON, the other as a Python dictionary:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"message = {\n    \"text_message\": {\n        \"text\": \"Text message from Sinch Conversation API.\"\n    }\n}\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\"message\": {\n    \"text_message\": {\n        \"text\": \"Text message from Sinch Conversation API.\"\n    }\n}    \n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note that, in both cases, the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["text_message"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["text"]}," objects are structured in exactly the same way as they would be in a normal Python call to the Conversation API. When using the Python SDK, any argument that represents a nested JSON object will be represented as a Python dictionary at the top level, but the contents of that dictionary must be represented as JSON objects. This is also highlighted in the below example:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"Python","header":{"controls":{"copy":{}}},"source":"\nrecipient={\n    \"identified_by\" : {\n        \"channel_identities\" : [\n            {\"identity\":\"RECIPIENT_number\",\"channel\" : \"SMS\"}\n        ]\n    }\n}\n\n","lang":"Python"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\n\"recipient\": {\n    \"identified_by\": {\n        \"channel_identities\": [\n            {\"identity\":\"RECIPIENT_number\",\"channel\" : \"SMS\"}  \n        ]\n    }\n}\n\n","lang":"JSON"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"responses-3","__idx":36},"children":["Responses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Response fields match the API responses. They are delivered as Python objects, with each top-level field represented as a property. Note that any nested objects normally returned by the Conversation API are returned as dictionaries by the Python SDK."]}]},"headings":[{"value":"Python SDK","id":"python-sdk","depth":1},{"value":"Client","id":"client","depth":2},{"value":"Initialization","id":"initialization","depth":3},{"value":"SMS API","id":"sms-api","depth":4},{"value":"Domains","id":"domains","depth":2},{"value":"Numbers Domain","id":"numbers-domain","depth":3},{"value":"Endpoint categories","id":"endpoint-categories","depth":4},{"value":"numbers endpoint category","id":"numbers-endpoint-category","depth":4},{"value":"numbers.regions endpoint category","id":"numbersregions-endpoint-category","depth":4},{"value":"event_destinations endpoint category","id":"event_destinations-endpoint-category","depth":4},{"value":"Request and query parameters","id":"request-and-query-parameters","depth":4},{"value":"Field name differences","id":"field-name-differences","depth":4},{"value":"Nested objects","id":"nested-objects","depth":4},{"value":"Responses","id":"responses","depth":4},{"value":"Number Lookup Domain","id":"number-lookup-domain","depth":3},{"value":"Endpoint categories","id":"endpoint-categories-1","depth":4},{"value":"lookup endpoint category","id":"lookup-endpoint-category","depth":4},{"value":"Request and query parameters","id":"request-and-query-parameters-1","depth":4},{"value":"Field name differences","id":"field-name-differences-1","depth":4},{"value":"Responses","id":"responses-1","depth":4},{"value":"SMS Domain","id":"sms-domain","depth":3},{"value":"Endpoint categories","id":"endpoint-categories-2","depth":4},{"value":"sms.batches endpoint category","id":"smsbatches-endpoint-category","depth":4},{"value":"delivery_reports endpoint category","id":"delivery_reports-endpoint-category","depth":4},{"value":"sms.sinch_events endpoint category","id":"smssinch_events-endpoint-category","depth":4},{"value":"Request and query parameters","id":"request-and-query-parameters-2","depth":4},{"value":"Field name differences","id":"field-name-differences-2","depth":4},{"value":"Nested objects","id":"nested-objects-1","depth":4},{"value":"Responses","id":"responses-2","depth":4},{"value":"Conversation Domain","id":"conversation-domain","depth":3},{"value":"Endpoint categories","id":"endpoint-categories-3","depth":4},{"value":"conversation.messages endpoint category","id":"conversationmessages-endpoint-category","depth":4},{"value":"conversation.sinch_events endpoint category","id":"conversationsinch_events-endpoint-category","depth":4},{"value":"Request and query parameters","id":"request-and-query-parameters-3","depth":4},{"value":"Field name differences","id":"field-name-differences-3","depth":4},{"value":"Nested objects","id":"nested-objects-2","depth":4},{"value":"Responses","id":"responses-3","depth":4}],"frontmatter":{"seo":{"title":"Python SDK | Sinch","description":"Read all about the Sinch Python SDK."},"product":"suite of Sinch APIs"},"lastModified":"2026-04-14T16:46:39.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/sdks/python","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}