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
Getting started
Client initialization
To initialize communication with Sinch backed, credentials obtained from Sinch portal have to be provided to the main client class of this SDK. It's highly advised to not hardcode those credentials, but to fetch them from environment variables:
from sinch import SinchClient
sinch_client = SinchClient(
key_id="key_id",
key_secret="key_secret",
project_id="some_project",
application_key="application_key",
application_secret="application_secret"
)
import os
from sinch import SinchClient
sinch_client = SinchClient(
key_id=os.getenv("KEY_ID"),
key_secret=os.getenv("KEY_SECRET"),
project_id=os.getenv("PROJECT_ID"),
application_key=os.getenv("APPLICATION_KEY"),
application_secret=os.getenv("APPLICATION_SECRET")
)
Products
Sinch client provides access to the following Sinch products:
- Numbers
- SMS
- Verification
- Voice API
- Conversation API (beta release)
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 NullHanlder provided by the standard logging module is advised.
Sample apps
Usage example of the numbers domain:
available_numbers = sinch_client.numbers.available.list(
region_code="US",
number_type="LOCAL"
)
Returned values are represented as Python dataclasses:
ListAvailableNumbersResponse(
available_numbers=[
Number(
phone_number='+17862045855',
region_code='US',
type='LOCAL',
capability=['SMS', 'VOICE'],
setup_price={'currency_code': 'EUR', 'amount': '0.80'},
monthly_price={'currency_code': 'EUR', 'amount': '0.80'}
...
Handling exceptions
Each API throws a custom, API related exception for an unsuccessful backed call.
Example for Numbers API:
from sinch.domains.numbers.exceptions import NumbersException
try:
nums = sinch_client.numbers.available.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, two HTTP implementations are provided:
- Synchronous using
requestsHTTP library - Asynchronous using
httpxHTTP library
For creating custom HTTP client code, use either SinchClient or SinchClientAsync client and inject your transport during initialisation:
sinch_client = SinchClientAsync(
key_id="Spanish",
key_secret="Inquisition",
project_id="some_project",
transport=MyHTTPAsyncImplementation
)
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
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-1.1.4.tar.gz.
File metadata
- Download URL: sinch-1.1.4.tar.gz
- Upload date:
- Size: 49.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ea0d6a28709b60ff602dc6fadf16176e0efe099564d499f87b9deecb4b20ff8
|
|
| MD5 |
f7fbaf5f8740f2f0aca28161a6b57cae
|
|
| BLAKE2b-256 |
86affbc229d03497872e5baa184680178d1cdcd8e8fe46fdd32f6d7316845fbd
|
File details
Details for the file sinch-1.1.4-py3-none-any.whl.
File metadata
- Download URL: sinch-1.1.4-py3-none-any.whl
- Upload date:
- Size: 147.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06b7717c9c7ced02e17d118e264886e66fbb1beeb4ab17b95cb2af2f9a75c7f9
|
|
| MD5 |
15cd32a4615299783b8100708919e13a
|
|
| BLAKE2b-256 |
6f449a1ab1a0adbbbf6a7a3f9993d603c108da9ae3d52b20a6faf3ee9efb1e1f
|