infobip-cpaasx


Nameinfobip-cpaasx JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/infobip/infobip-cpaasx-python-client
SummaryInfobip CPaaS X Python Client Library
upload_time2023-03-16 10:08:17
maintainer
docs_urlNone
authorInfobip Ltd.
requires_python
licenseMIT
keywords sms mms numbers cpaas infobip
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Infobip CPaaS X Python Client

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

This is a Python package for Infobip CpaaS X 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].

The package is built on top of [OpenAPI Specification](https://spec.openapis.org/oas/latest.html), generated by [Infobip OSCAR](https://www.youtube.com/watch?v=XC8oVn_efTw) service powered by [OpenAPI Generator](https://openapi-generator.tech/).

<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].

The current version of this library includes this subset of Infobip products:
* [Application and Entity Management](https://www.infobip.com/docs/api/platform/application-entity)
* [Numbers](https://www.infobip.com/docs/api/platform/numbers)
* [SMS](https://www.infobip.com/docs/api/channels/sms)
* [MMS](https://www.infobip.com/docs/api/channels/mms)

CPaaS X product documentation can be found [here](https://www.infobip.com/docs/cpaas-x).

## General Info
We use the [Semantic Versioning][semver] scheme.

The library is published under [MIT License][license].

Python 3.7 is minimum supported version by this library.

## Installation
Pull the library by using the following command:
```shell
pip install infobip_cpaasx
```

## 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_cpaasx import ApiClient, Configuration

    client_config = Configuration(
        host="<YOUR_BASE_URL>",
        api_key={"APIKeyHeader": "<YOUR_API_KEY>"},
        api_key_prefix={"APIKeyHeader": "App"},
    )
```

#### 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.

#### Create application
A basic example how to create an application.

```python
    application_request = Application(
        application_name="Application",
        application_id="application-id"
    )

    application_api = ApplicationApi(api_client)

    application_api.create_application(application=application_request)
```

#### Create entity
A basic example how to create an entity.

```python
    entity_request = Entity(
        entity_name="Entity",
        entity_id="entity-id"
    )

    entity_api = EntityApi(api_client)

    entity_api.create_entity(entity=entity_request)
```

#### Send an SMS
A basic example how to send an SMS message.

```python
    sms_request = SmsAdvancedTextualRequest(
        messages=[
            SmsTextualMessage(
                destinations=[
                    SmsDestination(
                        to="41793026727",
                    ),
                ],
                var_from="InfoSMS",
                text="This is a dummy SMS message sent using Python library",
                application_id="my-application-id",
                entity_id="my-entity-id"
            )
        ])

    sms_api = SmsApi(api_client)

    api_response: SmsResponse = sms_api.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_cpaasx import ApiException, SmsResponse

    try:
        api_response: SmsResponse = sms_api.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 = sms_api.send_sms_message(sms_advanced_textual_request=sms_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_results = SmsDeliveryResult.from_json(request.json)

        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 = sms_api.get_outbound_sms_message_delivery_reports(bulk_id=bulk_id, message_id=message_id)
    pprint(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 = sms_api.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))

```

#### Send an MMS
A basic example how to send an MMS message.

```python
    mms_request = MmsAdvancedRequest(
        bulk_id="bulk-id",
        messages=[
            MmsAdvancedMessage(
                destinations=[
                    MmsDestination(
                        to="41793026727"
                    )
                ],
                message_segments=[
                    MmsAdvancedMessageSegmentText(
                        content_id="content-id",
                        text="Message text"
                    ),
                    MmsAdvancedMessageSegmentLink(
                        content_id="content-id",
                        content_type="image/jpeg",
                        content_url="https://api.infobip.com/ott/1/media/infobipLogo"
                    )
                ],
                entity_id="my-entity-id",
                application_id="my-application-id"
            )
        ]
    )

    mms_api = MmsApi(api_client)

    api_response: MmsSendResult = mms_api.send_mms_message(mms_advanced_request=mms_request)
    pprint(api_response)
```

#### Get available numbers
A basic example for getting a list of available numbers.

```python
    numbers_api = NumbersApi(api_client)

    api_response: NumbersResponse = numbers_api.get_available_numbers(capabilities=["SMS"])

    pprint(api_response)
```

> **[All other examples can be found in tests](infobip_cpaasx/tests).**

## Ask for help

Feel free to open issues on the repository for any encountered problem or feature request. For pull requests, go to the `CONTRIBUTING` [file][contributing] related to it. This code is auto generated, and we are unable to merge any pull requests form here.

This code is auto generated, and we are unable to merge any pull request from here, but we will review and implement changes directly within our pipeline, as described in the `CONTRIBUTING` [file][contributing].

For anything that requires our imminent attention, contact us @ [support@infobip.com](mailto:support@infobip.com).

[apidocs]: https://www.infobip.com/docs/api
[freetrial]: https://www.infobip.com/docs/essentials/free-trial
[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-cpaasx-python-client",
    "name": "infobip-cpaasx",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "sms,mms,numbers,cpaas,infobip",
    "author": "Infobip Ltd.",
    "author_email": "support@infobip.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/4e/75e3da7a1c2c3210bfd2b84c0f65f056d3fd8b73e3465d2cca60b8220fc4/infobip_cpaasx-0.0.2.tar.gz",
    "platform": null,
    "description": "# Infobip CPaaS X Python Client\n\n[![Pypi index](https://badgen.net/pypi/v/infobip-cpaasx-python-client)](https://pypi.org/project/infobip-cpaasx-python-client/)\n[![MIT License](https://badgen.net/github/license/infobip/infobip-cpaasx-python-client)](https://opensource.org/licenses/MIT)\n\nThis is a Python package for Infobip CpaaS X 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\nThe package is built on top of [OpenAPI Specification](https://spec.openapis.org/oas/latest.html), generated by [Infobip OSCAR](https://www.youtube.com/watch?v=XC8oVn_efTw) service powered by [OpenAPI Generator](https://openapi-generator.tech/).\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\nThe current version of this library includes this subset of Infobip products:\n* [Application and Entity Management](https://www.infobip.com/docs/api/platform/application-entity)\n* [Numbers](https://www.infobip.com/docs/api/platform/numbers)\n* [SMS](https://www.infobip.com/docs/api/channels/sms)\n* [MMS](https://www.infobip.com/docs/api/channels/mms)\n\nCPaaS X product documentation can be found [here](https://www.infobip.com/docs/cpaas-x).\n\n## General Info\nWe use the [Semantic Versioning][semver] scheme.\n\nThe library is published under [MIT License][license].\n\nPython 3.7 is minimum supported version by this library.\n\n## Installation\nPull the library by using the following command:\n```shell\npip install infobip_cpaasx\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_cpaasx 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\": \"App\"},\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#### Create application\nA basic example how to create an application.\n\n```python\n    application_request = Application(\n        application_name=\"Application\",\n        application_id=\"application-id\"\n    )\n\n    application_api = ApplicationApi(api_client)\n\n    application_api.create_application(application=application_request)\n```\n\n#### Create entity\nA basic example how to create an entity.\n\n```python\n    entity_request = Entity(\n        entity_name=\"Entity\",\n        entity_id=\"entity-id\"\n    )\n\n    entity_api = EntityApi(api_client)\n\n    entity_api.create_entity(entity=entity_request)\n```\n\n#### Send an SMS\nA basic example how to send an SMS message.\n\n```python\n    sms_request = SmsAdvancedTextualRequest(\n        messages=[\n            SmsTextualMessage(\n                destinations=[\n                    SmsDestination(\n                        to=\"41793026727\",\n                    ),\n                ],\n                var_from=\"InfoSMS\",\n                text=\"This is a dummy SMS message sent using Python library\",\n                application_id=\"my-application-id\",\n                entity_id=\"my-entity-id\"\n            )\n        ])\n\n    sms_api = SmsApi(api_client)\n\n    api_response: SmsResponse = sms_api.send_sms_message(sms_advanced_textual_request=sms_request)\n    pprint(api_response)\n```\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_cpaasx import ApiException, SmsResponse\n\n    try:\n        api_response: SmsResponse = sms_api.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 = sms_api.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        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_results = SmsDeliveryResult.from_json(request.json)\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 = sms_api.get_outbound_sms_message_delivery_reports(bulk_id=bulk_id, message_id=message_id)\n    pprint(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 = sms_api.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\n#### Send an MMS\nA basic example how to send an MMS message.\n\n```python\n    mms_request = MmsAdvancedRequest(\n        bulk_id=\"bulk-id\",\n        messages=[\n            MmsAdvancedMessage(\n                destinations=[\n                    MmsDestination(\n                        to=\"41793026727\"\n                    )\n                ],\n                message_segments=[\n                    MmsAdvancedMessageSegmentText(\n                        content_id=\"content-id\",\n                        text=\"Message text\"\n                    ),\n                    MmsAdvancedMessageSegmentLink(\n                        content_id=\"content-id\",\n                        content_type=\"image/jpeg\",\n                        content_url=\"https://api.infobip.com/ott/1/media/infobipLogo\"\n                    )\n                ],\n                entity_id=\"my-entity-id\",\n                application_id=\"my-application-id\"\n            )\n        ]\n    )\n\n    mms_api = MmsApi(api_client)\n\n    api_response: MmsSendResult = mms_api.send_mms_message(mms_advanced_request=mms_request)\n    pprint(api_response)\n```\n\n#### Get available numbers\nA basic example for getting a list of available numbers.\n\n```python\n    numbers_api = NumbersApi(api_client)\n\n    api_response: NumbersResponse = numbers_api.get_available_numbers(capabilities=[\"SMS\"])\n\n    pprint(api_response)\n```\n\n> **[All other examples can be found in tests](infobip_cpaasx/tests).**\n\n## Ask for help\n\nFeel free to open issues on the repository for any encountered problem or feature request. For pull requests, go to the `CONTRIBUTING` [file][contributing] related to it. This code is auto generated, and we are unable to merge any pull requests form here.\n\nThis code is auto generated, and we are unable to merge any pull request from here, but we will review and implement changes directly within our pipeline, as described in the `CONTRIBUTING` [file][contributing].\n\nFor anything that requires our imminent attention, 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/essentials/free-trial\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 CPaaS X Python Client Library",
    "version": "0.0.2",
    "split_keywords": [
        "sms",
        "mms",
        "numbers",
        "cpaas",
        "infobip"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0a9af459a46f201a48514051bb99a8bfc090456d4650899e440f53707d13552f",
                "md5": "9ad69f40313c6d317f4b94b60b0ba865",
                "sha256": "43c703003dfa6c3a2a9b8dd9c7e650179938ef4273bc7baf60d6f9b855519d95"
            },
            "downloads": -1,
            "filename": "infobip_cpaasx-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ad69f40313c6d317f4b94b60b0ba865",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 244859,
            "upload_time": "2023-03-16T10:08:16",
            "upload_time_iso_8601": "2023-03-16T10:08:16.516270Z",
            "url": "https://files.pythonhosted.org/packages/0a/9a/f459a46f201a48514051bb99a8bfc090456d4650899e440f53707d13552f/infobip_cpaasx-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e4e75e3da7a1c2c3210bfd2b84c0f65f056d3fd8b73e3465d2cca60b8220fc4",
                "md5": "cfad4f7c7c79d118e30aba1408887445",
                "sha256": "c8610b0d7ec4076865b7c2fcf0f2001ae09429a6f94c335dcebf78f5c28ee5d3"
            },
            "downloads": -1,
            "filename": "infobip_cpaasx-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "cfad4f7c7c79d118e30aba1408887445",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 95271,
            "upload_time": "2023-03-16T10:08:17",
            "upload_time_iso_8601": "2023-03-16T10:08:17.979587Z",
            "url": "https://files.pythonhosted.org/packages/4e/4e/75e3da7a1c2c3210bfd2b84c0f65f056d3fd8b73e3465d2cca60b8220fc4/infobip_cpaasx-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-16 10:08:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "infobip",
    "github_project": "infobip-cpaasx-python-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "infobip-cpaasx"
}
        
Elapsed time: 0.81152s