Skip to main content

SMPP library for python

Project description

python-smpplib

Version Python versions PyPI downloads License CircleCI

SMPP library for Python. Forked from Google Code.

Example:

import logging
import sys

import smpplib.gsm
import smpplib.client
import smpplib.consts

# if you want to know what's happening
logging.basicConfig(level='DEBUG')

# Two parts, UCS2, SMS with UDH
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(u'Привет мир!\n'*10)

client = smpplib.client.Client('example.com', SOMEPORTNUMBER)

# Print when obtain message_id
client.set_message_sent_handler(
    lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))
client.set_message_received_handler(
    lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)))

client.connect()
client.bind_transceiver(system_id='login', password='secret')

for part in parts:
    pdu = client.send_message(
        source_addr_ton=smpplib.consts.SMPP_TON_INTL,
        #source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure it is a byte string, not unicode:
        source_addr='SENDERPHONENUM',

        dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
        #dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
        # Make sure thease two params are byte strings, not unicode:
        destination_addr='PHONENUMBER',
        short_message=part,

        data_coding=encoding_flag,
        esm_class=msg_type_flag,
        registered_delivery=True,
    )
    print(pdu.sequence)
client.listen()

You also may want to listen in a thread:

from threading import Thread
t = Thread(target=client.listen)
t.start()

The client supports setting a custom generator that produces sequence numbers for the PDU packages. Per default a simple in memory generator is used which in conclusion is reset on (re)instantiation of the client, e.g. by an application restart. If you want to keep the sequence number to be persisted across restarts you can implement your own storage backed generator.

Example:

import smpplib.client

import mymodule

generator = mymodule.PersistentSequenceGenerator()
client = smpplib.client.Client('example.com', SOMEPORTNUMBER, sequence_generator=generator)
...

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smpplib-2.0.1.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smpplib-2.0.1-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file smpplib-2.0.1.tar.gz.

File metadata

  • Download URL: smpplib-2.0.1.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for smpplib-2.0.1.tar.gz
Algorithm Hash digest
SHA256 fa8c191dea03dca6247a94f92cc2032c54819a2804f5897ddf6741c82711de1d
MD5 3f2128c7c4d6ebc7a9fd0f8f79fba954
BLAKE2b-256 071beaa2a41df512de45625ad8fe024016255650993cedc360ba46ccac170080

See more details on using hashes here.

File details

Details for the file smpplib-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: smpplib-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for smpplib-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4002f02e908d4b6de7893fd005683f60f6c5ec13bf9d73d3bca70ffab45fc037
MD5 0aabac37fb3da6f78f39e484be37dd1c
BLAKE2b-256 3fda377a478707c243ee070989dab01ebfd2d8d2a5dd6a1d8007527832c41861

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page