Package: sinch
Python SDKWelcome to Sinch's Python SDK.Here you'll find documentation to start developing Python code using Sinch services.To use this SDK you'll need a Sinch account and API keys. Please sign up atsinch.comFor more in depth version of the Sinch APIs, please refer to the official developer portal -developers.sinch.comThis SDK is currently available to selected developers for preview use only. It is being provided for the purpose of collecting feedback, and should not be used in production environments.InstallationGetting startedLoggingCustom HTTP client implementationInstallationYou can install this package to your virtual environment or to your global Python installation by cloning this repo and typing:pip install sinchGetting startedClient initializationTo 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:fromsinchimportClientsinch_client=Client(key_id="key_id",key_secret="key_secret",project_id="some_project")importosfromsinchimportClientsinch_client=Client(key_id=os.getenv("KEY_ID"),key_secret=os.getenv("KEY_SECRET"),project_id=os.getenv("PROJECT_ID"))DomainsEach product from Sinch portfolio is considered and coded as a separatedomain.
Domain contains data structures specific to that service, that can be also used by the developer.Abstract directory structure of thedomain:├── domain_name
│   ├── __init__.py (public interface of the domain)
│   ├── endpoints (directory with endpoint definitions)
│   ├── models (direcotry with data models definitions)
│   ├── enums.py (enums that can be helpful for a developer; e.g. SinchNumberType)
│   ├── exceptions.py (exceptions spefific for a particular domain; e.g. NumbersException)
│Sinch client provides access to the following Sinch product domains:NumbersConversation APISMSUsage example of thenumbersdomain:available_numbers=sinch_client.numbers.available.list(region_code="US",number_type="LOCAL")Returned values are represented as Pythondataclasses: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 exceptionsEach domain throws aDomainExceptionexception for an unsuccessful backed call.Example for Numbers Domain:fromsinch.domains.numbers.exceptionsimportNumbersExceptiontry:nums=sinch_client.numbers.available.list(region_code="US",number_type="LOCAL")exceptNumbersExceptionaserr:passFor handling all possible exceptions thrown by this SDK useSinchException(superclass of all Sinch exceptions) formsinch.core.exceptions.LoggingLogging configuration for this SDK utilizes following hierarchy:If no configuration was provided vialogger_nameorloggerconfigurable, SDK will inherit configuration from the root logger with theSinchprefix.Iflogger_nameconfigurable was provided, SDK will use logger related to that name. For example:myapp.sinchwill inherit configuration from themyapplogger.Iflogger(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 ofNullHanlderprovided by the standardloggingmodule is advised.Custom HTTP client implementationBy default, two HTTP implementations are provided:Synchronous usingrequestsHTTP libraryAsynchronous usingaiohttpHTTP libraryFor creating custom HTTP client code, use eitherClientorClientAsyncclient and inject your transport during initialisation:sinch_client=ClientAsync(key_id="Spanish",key_secret="Inquisition",project_id="some_project",transport=MyHTTPAsyncImplementation)Custom client has to obey types and methods described byHTTPTransportabstract base class:classHTTPTransport(ABC):@abstractmethoddefrequest(self,endpoint:HTTPEndpoint)->HTTPResponse:pass