sinch


Namesinch JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/sinch/sinch-sdk-python
SummarySinch SDK for Python programming language
upload_time2024-03-27 21:12:26
maintainerNone
docs_urlNone
authorSinch Developer Experience Team
requires_python>=3.9
licenseApache 2.0
keywords sinch sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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).

**This 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.**

- [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
- Conversation API
- Additional products coming soon!

## 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 `aiohttp` 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/ad/90/2389730465de6c3b699744ff5ced8784bd9b30f5e6775cf2b78a15817b2e/sinch-0.4.0.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**This 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.**\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- Conversation API\n- Additional products coming soon!\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 `aiohttp` 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": "0.4.0",
    "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": "e3aac36248eef152ef2be578939b9f0c7b5cac2171483255c504ce5fdf069112",
                "md5": "bb548dc620bcb96b03d3526842d11519",
                "sha256": "31278ace2e1360ae65859f8c3208e1a9bfd037fa76b8b52da2143adaf4b36f46"
            },
            "downloads": -1,
            "filename": "sinch-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bb548dc620bcb96b03d3526842d11519",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 122871,
            "upload_time": "2024-03-27T21:12:24",
            "upload_time_iso_8601": "2024-03-27T21:12:24.750716Z",
            "url": "https://files.pythonhosted.org/packages/e3/aa/c36248eef152ef2be578939b9f0c7b5cac2171483255c504ce5fdf069112/sinch-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ad902389730465de6c3b699744ff5ced8784bd9b30f5e6775cf2b78a15817b2e",
                "md5": "1d3968c6393559c259267b9c4968d8e9",
                "sha256": "aae76022aa8a1b316f506ed9389d0f566e6f946e669e8f940f9f79df5321764a"
            },
            "downloads": -1,
            "filename": "sinch-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1d3968c6393559c259267b9c4968d8e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 45884,
            "upload_time": "2024-03-27T21:12:26",
            "upload_time_iso_8601": "2024-03-27T21:12:26.818592Z",
            "url": "https://files.pythonhosted.org/packages/ad/90/2389730465de6c3b699744ff5ced8784bd9b30f5e6775cf2b78a15817b2e/sinch-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-27 21:12:26",
    "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"
}
        
Elapsed time: 0.21260s