infobip-api-python-client


Nameinfobip-api-python-client JSON
Version 3.0.3 PyPI version JSON
download
home_pagehttps://github.com/infobip/infobip-api-python-client
SummaryInfobip Client API Libraries OpenAPI Specification
upload_time2023-07-03 15:29:15
maintainer
docs_urlNone
authorInfobip Ltd.
requires_python>=3.6
licenseMIT
keywords infobip sms php tfa sdk rest api msisdn 2fa openapi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            

# Infobip API Python Client

[![Pypi index](https://badgen.net/pypi/v/infobip-api-python-client)](https://pypi.org/project/infobip-api-python-client/)
[![MIT License](https://badgen.net/github/license/infobip/infobip-api-python-client)](https://opensource.org/licenses/MIT)

This is a Python package for Infobip API and you can use it as a dependency to add [Infobip APIs][apidocs] to your application.
To use the package you'll need an Infobip account. If you don't already have one, you can create a [free trial][freetrial] account [here][signup].

We use [OpenAPI Generator](https://openapi-generator.tech/) to generate the package code from the OpenAPI specification.

<img src="https://udesigncss.com/wp-content/uploads/2020/01/Infobip-logo-transparent.png" height="124px" alt="Infobip" />

#### Table of contents:
* [API documentation](#documentation)
* [General Info](#general-info)
* [Installation](#installation)
* [Quickstart](#quickstart)
* [Ask for help](#ask-for-help)

## API documentation

Infobip API Documentation can be found [here][apidocs].

## General Info
For `infobip-api-python-client` versioning we use [Semantic Versioning][semver] scheme.

Published under [MIT License][license].

Python 3.6 is minimum supported version by this library.

## Installation
Pull the library by using the following command:
```shell
pip install infobip-api-python-client
```

## Quickstart

Before initializing the client first thing you need to do is to set configuration and authentication.

#### Configuration

Let's first set the configuration. For that you will need your specific URL. 
To see your base URL, log in to the [Infobip API Resource][apidocs] hub with your Infobip credentials.
```python
    from infobip_api_client.api_client import ApiClient, Configuration
    
    client_config = Configuration(
        host="<YOUR_BASE_URL>",
        api_key={"APIKeyHeader": "<YOUR_API_KEY>"},
        api_key_prefix={"APIKeyHeader": "<YOUR_API_PREFIX>"},
    )
```

#### Initialize the Client

With configuration set up you can initialize the API client.
```python
	api_client = ApiClient(client_config)
```

Now you are ready use the API.

#### Send an SMS
Here's a basic example of sending the SMS message.

```python
    sms_request = SmsAdvancedTextualRequest(
        messages=[
            SmsTextualMessage(
                destinations=[
                    SmsDestination(
                        to="41793026727",
                    ),
                ],
                _from="InfoSMS",
                text="This is a dummy SMS message sent using Python library",
            )
        ])
        
    api_instance = SendSmsApi(api_client)

    api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_textual_request=sms_request)
    pprint(api_response)
```

To make your code more robust send the message in try block and handle the `ApiException` in catch block.
```python
    from infobip_api_client.exceptions import ApiException
    
    try:
        api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_textual_request=sms_request)
    except ApiException as ex:
        print("Error occurred while trying to send SMS message.")
```

In case of failure you can inspect the `ApiException` for more information.
```python
    try:
        api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_binary_request=sms_advanced_binary_request)
    except ApiException as ex:
        print("Error occurred while trying to send SMS message.")
        print("Error status: %s\n" % ex.status)
        print("Error headers: %s\n" % ex.headers)
        print("Error body: %s\n" % ex.body)
```

Additionally, from the successful response (`SmsResponse` object) you can pull out the `bulk_id` and `message_id`(s) and use them to fetch a delivery report for given message or bulk.
Bulk ID will be received only when you send a message to more than one destination address or multiple messages in a single request.

```python
    bulk_id = api_response.bulk_id
    message_id = api_response.messages[0].message_id
```

#### Receive sent SMS report
For each SMS that you send out, we can send you a message delivery report in real time. All you need to do is specify your endpoint when sending SMS in `notify_url` field of `SmsTextualMessage`, or subscribe for reports by contacting our support team.
e.g. `https://{yourDomain}/delivery-reports`

Example of webhook implementation using Flask:

```python
    @app.route("/api/delivery-reports", methods=["POST"])
    def delivery_report():
        delivery_result = SmsDeliveryResult(
            results=request.json["results"]
        )
        
        for result in delivery_results.results:
            print("message {0} sent at {1}".format(result.message_id, result.sent_at))
```
If you prefer to use your own serializer, please pay attention to the supported [date format](https://www.infobip.com/docs/essentials/integration-best-practices#date-formats).

#### Fetching delivery reports
If you are for any reason unable to receive real time delivery reports on your endpoint, you can use `message_id` or `bulk_id` to fetch them.
Each request will return a batch of delivery reports. Please be aware that these can be retrieved only once.

```python
    api_response = api_instance.get_outbound_sms_message_delivery_reports(bulk_id=bulk_id, message_id=message_id, limit=2)
    print(api_response)
```

#### Unicode & SMS preview
Infobip API supports Unicode characters and automatically detects encoding. Unicode and non-standard GSM characters use additional space, avoid unpleasant surprises and check how different message configurations will affect your message text, number of characters and message parts.

```python
    sms_preview_request = SmsPreviewRequest(
        text="Let's see how many characters will remain unused in this message."
    )
    
    api_response = api_instance.preview_sms_message(sms_preview_request=sms_preview_request)
```

#### Receive incoming SMS
If you want to receive SMS messages from your subscribers we can have them delivered to you in real time. When you buy and configure a number capable of receiving SMS, specify your endpoint as explained [here](https://www.infobip.com/docs/api#channels/sms/receive-inbound-sms-messages).
e.g. `https://{yourDomain}/incoming-sms`.

Example of webhook implementation using Flask:

```python
    @app.route("/api/incoming-sms", methods=["POST"])
    def incoming_sms():
        message_results = SmsInboundMessageResult(
            message_count=request.json["message_count"],
            pending_message_count=request.json["pending_message_count"],
            results=request.json["results"]
        )
        
        for result in message_results.results:
            print("message text: {0}".format(result.clean_text))
        
```
#### Two-Factor Authentication (2FA)
For 2FA quick start guide please check [these examples](two-factor-authentication.md).

## Ask for help

Feel free to open issues on the repository for any issue or feature request. As per pull requests, for details check the `CONTRIBUTING` [file][contributing] related to it - in short, we will not merge any pull requests, this code is auto-generated.

If it's something that requires our imminent attention feel free to contact us @ [support@infobip.com](mailto:support@infobip.com).

[apidocs]: https://www.infobip.com/docs/api
[freetrial]: https://www.infobip.com/docs/freetrial
[signup]: https://www.infobip.com/signup
[semver]: https://semver.org
[license]: LICENSE
[contributing]: CONTRIBUTING.md

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/infobip/infobip-api-python-client",
    "name": "infobip-api-python-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "infobip,sms,php,tfa,sdk,rest,api,msisdn,2fa,openapi",
    "author": "Infobip Ltd.",
    "author_email": "support@infobip.com",
    "download_url": "https://files.pythonhosted.org/packages/fa/57/44fcd617af8ce3bb43828f297bc608922e7ef0bdc57fd91671abedfbff8c/infobip-api-python-client-3.0.3.tar.gz",
    "platform": null,
    "description": "\n\n# Infobip API Python Client\n\n[![Pypi index](https://badgen.net/pypi/v/infobip-api-python-client)](https://pypi.org/project/infobip-api-python-client/)\n[![MIT License](https://badgen.net/github/license/infobip/infobip-api-python-client)](https://opensource.org/licenses/MIT)\n\nThis is a Python package for Infobip API and you can use it as a dependency to add [Infobip APIs][apidocs] to your application.\nTo use the package you'll need an Infobip account. If you don't already have one, you can create a [free trial][freetrial] account [here][signup].\n\nWe use [OpenAPI Generator](https://openapi-generator.tech/) to generate the package code from the OpenAPI specification.\n\n<img src=\"https://udesigncss.com/wp-content/uploads/2020/01/Infobip-logo-transparent.png\" height=\"124px\" alt=\"Infobip\" />\n\n#### Table of contents:\n* [API documentation](#documentation)\n* [General Info](#general-info)\n* [Installation](#installation)\n* [Quickstart](#quickstart)\n* [Ask for help](#ask-for-help)\n\n## API documentation\n\nInfobip API Documentation can be found [here][apidocs].\n\n## General Info\nFor `infobip-api-python-client` versioning we use [Semantic Versioning][semver] scheme.\n\nPublished under [MIT License][license].\n\nPython 3.6 is minimum supported version by this library.\n\n## Installation\nPull the library by using the following command:\n```shell\npip install infobip-api-python-client\n```\n\n## Quickstart\n\nBefore initializing the client first thing you need to do is to set configuration and authentication.\n\n#### Configuration\n\nLet's first set the configuration. For that you will need your specific URL. \nTo see your base URL, log in to the [Infobip API Resource][apidocs] hub with your Infobip credentials.\n```python\n    from infobip_api_client.api_client import ApiClient, Configuration\n    \n    client_config = Configuration(\n        host=\"<YOUR_BASE_URL>\",\n        api_key={\"APIKeyHeader\": \"<YOUR_API_KEY>\"},\n        api_key_prefix={\"APIKeyHeader\": \"<YOUR_API_PREFIX>\"},\n    )\n```\n\n#### Initialize the Client\n\nWith configuration set up you can initialize the API client.\n```python\n\tapi_client = ApiClient(client_config)\n```\n\nNow you are ready use the API.\n\n#### Send an SMS\nHere's a basic example of sending the SMS message.\n\n```python\n    sms_request = SmsAdvancedTextualRequest(\n        messages=[\n            SmsTextualMessage(\n                destinations=[\n                    SmsDestination(\n                        to=\"41793026727\",\n                    ),\n                ],\n                _from=\"InfoSMS\",\n                text=\"This is a dummy SMS message sent using Python library\",\n            )\n        ])\n        \n    api_instance = SendSmsApi(api_client)\n\n    api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_textual_request=sms_request)\n    pprint(api_response)\n```\n\nTo make your code more robust send the message in try block and handle the `ApiException` in catch block.\n```python\n    from infobip_api_client.exceptions import ApiException\n    \n    try:\n        api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_textual_request=sms_request)\n    except ApiException as ex:\n        print(\"Error occurred while trying to send SMS message.\")\n```\n\nIn case of failure you can inspect the `ApiException` for more information.\n```python\n    try:\n        api_response: SmsResponse = api_instance.send_sms_message(sms_advanced_binary_request=sms_advanced_binary_request)\n    except ApiException as ex:\n        print(\"Error occurred while trying to send SMS message.\")\n        print(\"Error status: %s\\n\" % ex.status)\n        print(\"Error headers: %s\\n\" % ex.headers)\n        print(\"Error body: %s\\n\" % ex.body)\n```\n\nAdditionally, from the successful response (`SmsResponse` object) you can pull out the `bulk_id` and `message_id`(s) and use them to fetch a delivery report for given message or bulk.\nBulk ID will be received only when you send a message to more than one destination address or multiple messages in a single request.\n\n```python\n    bulk_id = api_response.bulk_id\n    message_id = api_response.messages[0].message_id\n```\n\n#### Receive sent SMS report\nFor each SMS that you send out, we can send you a message delivery report in real time. All you need to do is specify your endpoint when sending SMS in `notify_url` field of `SmsTextualMessage`, or subscribe for reports by contacting our support team.\ne.g. `https://{yourDomain}/delivery-reports`\n\nExample of webhook implementation using Flask:\n\n```python\n    @app.route(\"/api/delivery-reports\", methods=[\"POST\"])\n    def delivery_report():\n        delivery_result = SmsDeliveryResult(\n            results=request.json[\"results\"]\n        )\n        \n        for result in delivery_results.results:\n            print(\"message {0} sent at {1}\".format(result.message_id, result.sent_at))\n```\nIf you prefer to use your own serializer, please pay attention to the supported [date format](https://www.infobip.com/docs/essentials/integration-best-practices#date-formats).\n\n#### Fetching delivery reports\nIf you are for any reason unable to receive real time delivery reports on your endpoint, you can use `message_id` or `bulk_id` to fetch them.\nEach request will return a batch of delivery reports. Please be aware that these can be retrieved only once.\n\n```python\n    api_response = api_instance.get_outbound_sms_message_delivery_reports(bulk_id=bulk_id, message_id=message_id, limit=2)\n    print(api_response)\n```\n\n#### Unicode & SMS preview\nInfobip API supports Unicode characters and automatically detects encoding. Unicode and non-standard GSM characters use additional space, avoid unpleasant surprises and check how different message configurations will affect your message text, number of characters and message parts.\n\n```python\n    sms_preview_request = SmsPreviewRequest(\n        text=\"Let's see how many characters will remain unused in this message.\"\n    )\n    \n    api_response = api_instance.preview_sms_message(sms_preview_request=sms_preview_request)\n```\n\n#### Receive incoming SMS\nIf you want to receive SMS messages from your subscribers we can have them delivered to you in real time. When you buy and configure a number capable of receiving SMS, specify your endpoint as explained [here](https://www.infobip.com/docs/api#channels/sms/receive-inbound-sms-messages).\ne.g. `https://{yourDomain}/incoming-sms`.\n\nExample of webhook implementation using Flask:\n\n```python\n    @app.route(\"/api/incoming-sms\", methods=[\"POST\"])\n    def incoming_sms():\n        message_results = SmsInboundMessageResult(\n            message_count=request.json[\"message_count\"],\n            pending_message_count=request.json[\"pending_message_count\"],\n            results=request.json[\"results\"]\n        )\n        \n        for result in message_results.results:\n            print(\"message text: {0}\".format(result.clean_text))\n        \n```\n#### Two-Factor Authentication (2FA)\nFor 2FA quick start guide please check [these examples](two-factor-authentication.md).\n\n## Ask for help\n\nFeel free to open issues on the repository for any issue or feature request. As per pull requests, for details check the `CONTRIBUTING` [file][contributing] related to it - in short, we will not merge any pull requests, this code is auto-generated.\n\nIf it's something that requires our imminent attention feel free to contact us @ [support@infobip.com](mailto:support@infobip.com).\n\n[apidocs]: https://www.infobip.com/docs/api\n[freetrial]: https://www.infobip.com/docs/freetrial\n[signup]: https://www.infobip.com/signup\n[semver]: https://semver.org\n[license]: LICENSE\n[contributing]: CONTRIBUTING.md\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Infobip Client API Libraries OpenAPI Specification",
    "version": "3.0.3",
    "project_urls": {
        "Homepage": "https://github.com/infobip/infobip-api-python-client"
    },
    "split_keywords": [
        "infobip",
        "sms",
        "php",
        "tfa",
        "sdk",
        "rest",
        "api",
        "msisdn",
        "2fa",
        "openapi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25d6272ab3692efe914d3ff017b115632c835695736657f3b97a663d9aa16137",
                "md5": "c1ec51bd7cafe633ddd75e7cf1c2cd6b",
                "sha256": "81ed6971d5e73edebb225d70cc06c693067ca53c1af7a80cfa551b18390466ce"
            },
            "downloads": -1,
            "filename": "infobip_api_python_client-3.0.3-py3.9.egg",
            "has_sig": false,
            "md5_digest": "c1ec51bd7cafe633ddd75e7cf1c2cd6b",
            "packagetype": "bdist_egg",
            "python_version": "3.0.3",
            "requires_python": ">=3.6",
            "size": 414724,
            "upload_time": "2023-07-03T15:29:14",
            "upload_time_iso_8601": "2023-07-03T15:29:14.501957Z",
            "url": "https://files.pythonhosted.org/packages/25/d6/272ab3692efe914d3ff017b115632c835695736657f3b97a663d9aa16137/infobip_api_python_client-3.0.3-py3.9.egg",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2576ab0d3eeafb7d3845b69e7de6361935cba7f37fc896a5d29666d09478d712",
                "md5": "051d16bb49d650dc9e7fc77da89724ab",
                "sha256": "ff34bd99442ac5a564d639b20a750d843900cf396fe4f9e279250de8ce481564"
            },
            "downloads": -1,
            "filename": "infobip_api_python_client-3.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "051d16bb49d650dc9e7fc77da89724ab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 191487,
            "upload_time": "2023-07-03T15:29:12",
            "upload_time_iso_8601": "2023-07-03T15:29:12.246566Z",
            "url": "https://files.pythonhosted.org/packages/25/76/ab0d3eeafb7d3845b69e7de6361935cba7f37fc896a5d29666d09478d712/infobip_api_python_client-3.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa5744fcd617af8ce3bb43828f297bc608922e7ef0bdc57fd91671abedfbff8c",
                "md5": "056f68add73c684e7db65f24832f352f",
                "sha256": "3c8809296e71b2bd222a88413f5378041fc6c298af99e2143835f8f5d88a70c7"
            },
            "downloads": -1,
            "filename": "infobip-api-python-client-3.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "056f68add73c684e7db65f24832f352f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 67230,
            "upload_time": "2023-07-03T15:29:15",
            "upload_time_iso_8601": "2023-07-03T15:29:15.916371Z",
            "url": "https://files.pythonhosted.org/packages/fa/57/44fcd617af8ce3bb43828f297bc608922e7ef0bdc57fd91671abedfbff8c/infobip-api-python-client-3.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-03 15:29:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "infobip",
    "github_project": "infobip-api-python-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "infobip-api-python-client"
}
        
Elapsed time: 0.08408s