# Sinch Python SDK
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/sinch/sinch-sdk-python/blob/main/LICENSE)
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3100/)
[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-3110/)
[![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3120/)
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](https://dashboard.sinch.com).
For more information on the Sinch APIs on which this SDK is based, refer to the official [developer documentation portal](developers.sinch.com).
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Getting started](#getting-started)
- [Logging]()
## Prerequisites
- Python in one of the supported versions - 3.9, 3.10, 3.11, 3.12
- 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:
```python
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"
)
```
```python
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:
1. If no configuration was provided via `logger_name` or `logger` configurable, SDK will inherit configuration from the root logger with the `Sinch` prefix.
2. If `logger_name` configurable was provided, SDK will use logger related to that name. For example: `myapp.sinch` will inherit configuration from the `myapp` logger.
3. 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:
```python
available_numbers = sinch_client.numbers.available.list(
region_code="US",
number_type="LOCAL"
)
```
Returned values are represented as Python `dataclasses`:
```python
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:
```python
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 `requests` HTTP library
- Asynchronous using `httpx` HTTP library
For creating custom HTTP client code, use either `SinchClient` or `SinchClientAsync` client and inject your transport during initialisation:
```python
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:
```python
class HTTPTransport(ABC):
@abstractmethod
def request(self, endpoint: HTTPEndpoint) -> HTTPResponse:
pass
```
## License
This project is licensed under the Apache License. See the [LICENSE](license.md) file for the license text.
Raw data
{
"_id": null,
"home_page": "https://github.com/sinch/sinch-sdk-python",
"name": "sinch",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "sinch, sdk",
"author": "Sinch Developer Experience Team",
"author_email": "devexp@sinch.com",
"download_url": "https://files.pythonhosted.org/packages/07/24/433c1b7002c4096efe85c42b86dec9581682a34e56baa35121671635dbc4/sinch-1.1.1.tar.gz",
"platform": null,
"description": "# Sinch Python SDK\n\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/sinch/sinch-sdk-python/blob/main/LICENSE)\n\n\n[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)\n[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3100/)\n[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-3110/)\n[![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3120/)\n\n\n\nHere 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.\n\nTo 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](https://dashboard.sinch.com).\n\nFor more information on the Sinch APIs on which this SDK is based, refer to the official [developer documentation portal](developers.sinch.com).\n\n\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Getting started](#getting-started)\n- [Logging]()\n\n## Prerequisites\n\n- Python in one of the supported versions - 3.9, 3.10, 3.11, 3.12\n- pip\n- Sinch account\n\n## Installation\n\nYou can install this package by typing:\n`pip install sinch`\n\n## Getting started\n\n### Client initialization\n\n\nTo initialize communication with Sinch backed, credentials obtained from Sinch portal have to be provided to the main client class of this SDK.\nIt's highly advised to not hardcode those credentials, but to fetch them from environment variables:\n\n```python\nfrom sinch import SinchClient\n\nsinch_client = SinchClient(\n key_id=\"key_id\",\n key_secret=\"key_secret\",\n project_id=\"some_project\",\n application_key=\"application_key\",\n application_secret=\"application_secret\"\n)\n```\n\n```python\nimport 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 application_key=os.getenv(\"APPLICATION_KEY\"),\n application_secret=os.getenv(\"APPLICATION_SECRET\")\n)\n```\n\n## Products\n\nSinch client provides access to the following Sinch products:\n- Numbers\n- SMS\n- Verification\n- Voice API\n- Conversation API (beta release)\n\n## Logging\n\nLogging configuration for this SDK utilizes following hierarchy:\n1. If no configuration was provided via `logger_name` or `logger` configurable, SDK will inherit configuration from the root logger with the `Sinch` prefix.\n2. If `logger_name` configurable was provided, SDK will use logger related to that name. For example: `myapp.sinch` will inherit configuration from the `myapp` logger.\n3. If `logger` (logger instance) configurable was provided, SDK will use that particular logger for all its logging operations.\n\nIf all logging returned by this SDK needs to be disabled, usage of `NullHanlder` provided by the standard `logging` module is advised. \n\n\n \n## Sample apps\n\nUsage example of the `numbers` domain:\n\n```python\navailable_numbers = sinch_client.numbers.available.list(\n region_code=\"US\",\n number_type=\"LOCAL\"\n)\n```\nReturned values are represented as Python `dataclasses`:\n\n```python\nListAvailableNumbersResponse(\n available_numbers=[\n Number(\n phone_number='+17862045855',\n region_code='US',\n type='LOCAL',\n capability=['SMS', 'VOICE'],\n setup_price={'currency_code': 'EUR', 'amount': '0.80'},\n monthly_price={'currency_code': 'EUR', 'amount': '0.80'}\n ...\n```\n\n### Handling exceptions\n\nEach API throws a custom, API related exception for an unsuccessful backed call.\n\nExample for Numbers API:\n\n```python\nfrom sinch.domains.numbers.exceptions import NumbersException\n\ntry:\n nums = sinch_client.numbers.available.list(\n region_code=\"US\",\n number_type=\"LOCAL\"\n )\nexcept NumbersException as err:\n pass\n```\n\nFor handling all possible exceptions thrown by this SDK use `SinchException` (superclass of all Sinch exceptions) from `sinch.core.exceptions`.\n\n\n## Custom HTTP client implementation\n\nBy default, two HTTP implementations are provided:\n- Synchronous using `requests` HTTP library\n- Asynchronous using `httpx` HTTP library\n\nFor creating custom HTTP client code, use either `SinchClient` or `SinchClientAsync` client and inject your transport during initialisation:\n```python\nsinch_client = SinchClientAsync(\n key_id=\"Spanish\",\n key_secret=\"Inquisition\",\n project_id=\"some_project\",\n transport=MyHTTPAsyncImplementation\n)\n```\n\nCustom client has to obey types and methods described by `HTTPTransport` abstract base class:\n```python\nclass HTTPTransport(ABC):\n @abstractmethod\n def request(self, endpoint: HTTPEndpoint) -> HTTPResponse:\n pass\n```\n## License\n\nThis project is licensed under the Apache License. See the [LICENSE](license.md) file for the license text.\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Sinch SDK for Python programming language",
"version": "1.1.1",
"project_urls": {
"Documentation": "https://developers.sinch.com",
"Homepage": "https://github.com/sinch/sinch-sdk-python",
"Repository": "https://github.com/sinch/sinch-sdk-python"
},
"split_keywords": [
"sinch",
" sdk"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d9d8a006cbdd69bc04dd8e70f9f2b10a10140782720141e6b66cafae1704e6a3",
"md5": "58afd970adb41c906742913aa4db8e32",
"sha256": "88599b6232f52040c6e9c652a358bc1cfdcc0c2070748c37bd685537c97ecb64"
},
"downloads": -1,
"filename": "sinch-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "58afd970adb41c906742913aa4db8e32",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 147504,
"upload_time": "2024-12-19T15:09:46",
"upload_time_iso_8601": "2024-12-19T15:09:46.519958Z",
"url": "https://files.pythonhosted.org/packages/d9/d8/a006cbdd69bc04dd8e70f9f2b10a10140782720141e6b66cafae1704e6a3/sinch-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0724433c1b7002c4096efe85c42b86dec9581682a34e56baa35121671635dbc4",
"md5": "a2fdc72c54485cbce8bc6f9032afcab8",
"sha256": "d5a557fed9770fec9db74b7c243307abfe1423578d3674638dd2c89831e8e04f"
},
"downloads": -1,
"filename": "sinch-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "a2fdc72c54485cbce8bc6f9032afcab8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 53641,
"upload_time": "2024-12-19T15:09:48",
"upload_time_iso_8601": "2024-12-19T15:09:48.902856Z",
"url": "https://files.pythonhosted.org/packages/07/24/433c1b7002c4096efe85c42b86dec9581682a34e56baa35121671635dbc4/sinch-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-19 15:09:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sinch",
"github_project": "sinch-sdk-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sinch"
}