Skip to main content

Infobip CPaaS X Python Client

Pypi index MIT License

This is a Python package for Infobip CpaaS X API and you can use it as a dependency to add Infobip APIs 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 account here.

The package is built on top of OpenAPI Specification, generated by Infobip OSCAR service powered by OpenAPI Generator.

Infobip

Table of contents:

API documentation

Infobip API Documentation can be found here.

The current version of this library includes this subset of Infobip products:

CPaaS X product documentation can be found here.

General Info

We use the Semantic Versioning scheme.

The library is published under MIT License.

Python 3.7 is minimum supported version by this library.

Installation

Pull the library by using the following command:

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 hub with your Infobip credentials.

    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.

	api_client = ApiClient(client_config)

Now you are ready use the API.

Create application

A basic example how to create an application.

    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.

    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.

    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.

    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.

    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.

    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:

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

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.

    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.

    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. e.g. https://{yourDomain}/incoming-sms.

Example of webhook implementation using Flask:

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

    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.

    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.

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

For anything that requires our imminent attention, contact us @ support@infobip.com.

Metadata

Release files for infobip-cpaasx 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for infobip-cpaasx 0.0.2
File Size Uploaded Provenance Actions
infobip_cpaasx-0.0.2.tar.gz 95.3 kB Without provenance Details for infobip_cpaasx-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for infobip-cpaasx 0.0.2
File Interpreter ABI Platform Actions
infobip_cpaasx-0.0.2-py3-none-any.whl Python 3 none any Details for infobip_cpaasx-0.0.2-py3-none-any.whl

Total release size: 340.1 kB

Release files / infobip_cpaasx-0.0.2.tar.gz

Download URL infobip_cpaasx-0.0.2.tar.gz
Size 95.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c8610b0d7ec4076865b7c2fcf0f2001ae09429a6f94c335dcebf78f5c28ee5d3
BLAKE2b-256 checksum
How to use checksums
4e4e75e3da7a1c2c3210bfd2b84c0f65f056d3fd8b73e3465d2cca60b8220fc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / infobip_cpaasx-0.0.2-py3-none-any.whl

Download URL infobip_cpaasx-0.0.2-py3-none-any.whl
Size 244.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43c703003dfa6c3a2a9b8dd9c7e650179938ef4273bc7baf60d6f9b855519d95
BLAKE2b-256 checksum
How to use checksums
0a9af459a46f201a48514051bb99a8bfc090456d4650899e440f53707d13552f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Security for infobip-cpaasx 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page