Skip to main content

SMPP library for python

Project description

python-smpplib

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.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

smpplib-2.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smpplib-2.0.tar.gz
  • Upload date:
  • Size: 19.4 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.tar.gz
Algorithm Hash digest
SHA256 96605460f14a503579aecc7f182431537b9708c36a3c0838c499d8904dc3fe95
MD5 917b43b7b063462cc71474fa076e5ca8
BLAKE2b-256 89d9c0d71a39b0387134df90442b4374d17688f351976e3a28d95d9f90eaa5c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smpplib-2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 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-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc3611201e2aa1ef701d7ea7e081fd33cb0ce398a2b4fa59fc7822ded594438
MD5 55d0c675c74755dab61eb257fc98996b
BLAKE2b-256 a94981f8c8fb0ed761270e7003b1be98eb1518af1ee857d86a5e7f1a7e00ca0e

See more details on using hashes here.

Supported by

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