This repository contains the open source Python client for BSG REST API. The API allows you to send bulk SMS campaigns, single transactional SMS, Viber messages, and check phone numbers via HLR requests. The API usage is free. You only pay for the messages sent.
Prices for sending messages can be found here: Prices
For access to BSG API:
For development:
Download repository, decompress, install with
setup.py install
See BSG REST API Documentation for complete list of API clients, error codes, result codes etc.
An short example of a SMS API usage:
importpprintimportbsg_restapiasapifromexamples.settingsimportAPI_KEYclient=api.SMSAPI(config={'api_key': API_KEY})
result=client.send(message=api.SMSMessage(body='test message text'), recipients=api.Recipient(380967770002))
print('Result of SMS sending:\n{}'.format(pprint.pformat(result)))
# getting status of SMSstatus=client.get_status(result['reference'])
print('Current SMS status result for reference {}: \n{}'.format(result['reference'], pprint.pformat(status, indent=4)))An example of a HLR API usage:
importpprintimportbsg_restapiasapifromexamples.settingsimportAPI_KEY# Create HLR API Clientclient=api.HLRAPI(config={'api_key': API_KEY})
# Get prices for HLRprices=client.get_prices()
print('HLR Prices (first 5 elements from {}): \n{}'.format(len(prices), pprint.pformat(prices[0:5], indent=4)))
# Get HLR for single smisdn:lookup_list=api.HLRL(380970000000)
print('Created HLR request: \n{}'.format(pprint.pformat(lookup_list, indent=4)))
# Send the requestresult=client.send(lookup_list)
# Get server responseresult_id=result['result'][0]['id']
# Get status of HLR by result_id:status_id=client.get_status(result_id)
# Try the same for 'reference'result_ref=result['result'][0]['reference']
status_ref=client.get_status(result_ref)
# and print the resultprint('Current HLR response by id: \n{}'.format(pprint.pformat(status_id, indent=4)))
print('Current HLR response by reference: \n{}'.format(pprint.pformat(status_ref, indent=4)))See examples subfolder for
- samples of usage,
- various API processing and error handling aspects,
- examples for client's SSL certificate and proxy usage.