Sinch SDK for Python programming language
Project description
Sinch Python SDK
Here you'll find documentation related to the Sinch Python SDK, including how to install it, initialize it, and start developing Python code using Sinch services.
To use Sinch services, you'll need a Sinch account and access keys. You can sign up for an account and create access keys at dashboard.sinch.com.
For more information on the Sinch APIs on which this SDK is based, refer to the official developer documentation portal.
Prerequisites
- Python in one of the supported versions - 3.9, 3.10, 3.11, 3.12, 3.13, 3.14
- pip
- Sinch account
Installation
You can install this package by typing:
pip install sinch
Products
The Sinch client provides access to the following Sinch products:
- Numbers API
- SMS API
- Conversation API (beta release)
Getting started
Client initialization
To establish a connection with the Sinch backend, you must provide the appropriate credentials based on the API you intend to use. For security best practices, avoid hardcoding credentials. Instead, retrieve them from environment variables.
SMS API
For the SMS API in Australia (AU), Brazil (BR), Canada (CA), the United States (US), and the European Union (EU), provide the following parameters:
from sinch import SinchClient
sinch_client = SinchClient(
service_plan_id="service_plan_id",
sms_api_token="api_token"
)
All Other Sinch APIs
For all other Sinch APIs, including SMS in US and EU regions, use the following parameters:
from sinch import SinchClient
sinch_client = SinchClient(
project_id="project_id",
key_id="key_id",
key_secret="key_secret"
)
SMS and Conversation regions (V2)
You must set sms_region before using the SMS API and conversation_region before using the Conversation API—either in the SinchClient(...) constructor or on sinch_client.configuration before the first call to that product. See MIGRATION_GUIDE.md for examples.
Logging
Logging configuration for this SDK utilizes following hierarchy:
- If no configuration was provided via
logger_nameorloggerconfigurable, SDK will inherit configuration from the root logger with theSinchprefix. - If
logger_nameconfigurable was provided, SDK will use logger related to that name. For example:myapp.sinchwill inherit configuration from themyapplogger. - If
logger(logger instance) configurable was provided, SDK will use that particular logger for all its logging operations.
If all logging returned by this SDK needs to be disabled, usage of NullHandler provided by the standard logging module is advised.
Sample apps
Usage example of the Numbers API via VirtualNumbers on the client (sinch_client.numbers)—list() returns your project’s active virtual numbers:
paginator = sinch_client.numbers.list(
region_code="US",
number_type="LOCAL",
)
for active_number in paginator.iterator():
print(active_number)
Returned values are Pydantic model instances (for example ActiveNumber), including fields such as phone_number, region_code, type, and capabilities.
More examples live under examples/snippets on the main branch.
Handling exceptions
Each API throws a custom, API related exception for an unsuccessful backed call.
Example for Numbers API:
from sinch.domains.numbers.api.v1.exceptions import NumbersException
try:
paginator = sinch_client.numbers.list(
region_code="US",
number_type="LOCAL",
)
except NumbersException as err:
pass
For handling all possible exceptions thrown by this SDK use SinchException (superclass of all Sinch exceptions) from sinch.core.exceptions.
Custom HTTP client implementation
By default, the HTTP implementation uses the requests library.
To use a custom HTTP client, inject your own transport during initialization:
sinch_client = SinchClient(
key_id="key_id",
key_secret="key_secret",
project_id="some_project",
transport=MyHTTPImplementation
)
Custom client has to obey types and methods described by HTTPTransport abstract base class:
class HTTPTransport(ABC):
@abstractmethod
def request(self, endpoint: HTTPEndpoint) -> HTTPResponse:
pass
Note: Asynchronous HTTP clients are not supported. The transport must be a synchronous implementation.
License
This project is licensed under the Apache License. See the LICENSE file for the license text.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sinch-2.0.0.tar.gz.
File metadata
- Download URL: sinch-2.0.0.tar.gz
- Upload date:
- Size: 93.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3261449574fcd9661ece4c1829d4dd1ca65168001b6d964920c109e51a6489a9
|
|
| MD5 |
73e5048f58eaa05f8e4631444da29892
|
|
| BLAKE2b-256 |
1ad698a90148c7a80704b87389865d3891a06d7fc69e81d7b183362383891b85
|
File details
Details for the file sinch-2.0.0-py3-none-any.whl.
File metadata
- Download URL: sinch-2.0.0-py3-none-any.whl
- Upload date:
- Size: 278.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ec4f49287ce85ed8ef03fd9a6b6bc6da92d21039bc0f9aa785def816687b89a
|
|
| MD5 |
1b08393e32190f6ba84184847af79542
|
|
| BLAKE2b-256 |
c18a72478e4fb9e8cbdf30315e56aea18faffbb28bab3173f5b34d157e732d0f
|