# 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
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
infobip-api-python-client-3.0.1.tar.gz (80个子文件)
infobip-api-python-client-3.0.1
PKG-INFO 8KB
infobip_api_client
model_utils.py 72KB
model
tfa_application_response.py 7KB
tfa_pin_type.py 7KB
sms_regional_options.py 7KB
tfa_verify_pin_request.py 6KB
tfa_start_authentication_response.py 7KB
sms_delivery_time_window.py 7KB
sms_advanced_binary_request.py 8KB
sms_error.py 7KB
tfa_api_request_error_details.py 7KB
sms_delivery_time.py 7KB
sms_advanced_textual_request.py 8KB
tfa_api_request_error.py 7KB
sms_response_details.py 7KB
sms_bulk_request.py 6KB
tfa_application_configuration.py 10KB
sms_tracking.py 7KB
sms_sending_speed_limit.py 7KB
sms_api_exception.py 7KB
sms_api_request_error.py 7KB
sms_textual_message.py 11KB
sms_update_status_request.py 7KB
sms_language_configuration.py 7KB
sms_binary_message.py 10KB
sms_price.py 7KB
sms_status.py 7KB
__init__.py 348B
sms_api_request_error_details.py 7KB
sms_preview_response.py 7KB
tfa_api_exception.py 7KB
sms_delivery_result.py 6KB
sms_speed_limit_time_unit.py 7KB
sms_inbound_message_result.py 7KB
tfa_message.py 9KB
sms_bulk_status_response.py 7KB
tfa_verification.py 7KB
sms_log.py 9KB
sms_destination.py 7KB
tfa_create_message_request.py 9KB
tfa_language.py 7KB
sms_inbound_message.py 8KB
tfa_regional_options.py 7KB
tfa_verification_response.py 7KB
sms_bulk_response.py 6KB
tfa_india_dlt_options.py 7KB
sms_preview.py 7KB
tfa_resend_pin_request.py 7KB
sms_response.py 7KB
sms_logs_response.py 6KB
tfa_start_authentication_request.py 8KB
sms_preview_request.py 7KB
sms_india_dlt_options.py 7KB
sms_delivery_day.py 7KB
tfa_update_message_request.py 9KB
sms_report.py 9KB
sms_language.py 7KB
sms_bulk_status.py 7KB
tfa_application_request.py 7KB
tfa_verify_pin_response.py 7KB
sms_binary_content.py 7KB
configuration.py 18KB
api
tfa_api.py 60KB
receive_sms_api.py 5KB
send_sms_api.py 24KB
__init__.py 225B
scheduled_sms_api.py 17KB
__init__.py 854B
api_client.py 35KB
rest.py 13KB
exceptions.py 5KB
infobip_api_python_client.egg-info
PKG-INFO 8KB
requires.txt 32B
SOURCES.txt 3KB
top_level.txt 19B
dependency_links.txt 1B
LICENSE 1KB
setup.cfg 69B
setup.py 2KB
README.md 7KB
共 80 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 解决未在远程桌面会话中捕获到鼠标,vmguest.iso软件分享给大家
- JSP+SQL基于WEB的开放性实验管理系统设计与实现(源代码+论文+开题报告+中英文献+答辩PPT).rar
- log4net配置文件!!!!!!!!!!!!!!!!!
- 河南统计面板数据集(2010-2022年).xlsx
- OrcaleDBHelper帮助类!!!!!!!!!!!!
- log4net帮助类,用来写日志!!!!!!!!!!!!!
- Windows10时间同步源
- 信呼OA系统2.1.7版源码
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功