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, allow_unknown_opt_params=True)

# 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)
    
# Enters a loop, waiting for incoming PDUs
client.listen()

You also may want to listen in a thread:

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

Note: When listening, the client will automatically send an enquire_link command when the socket timeouts. You may override that behavior by passing auto_send_enquire_link=False as an argument to listen(). In that case, socket.timeout exceptions will bubble up.

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.2.2.tar.gz (24.8 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.2.2-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smpplib-2.2.2.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for smpplib-2.2.2.tar.gz
Algorithm Hash digest
SHA256 f2191e73b24dba94f2889bf2ea1a60aeef6bd43afd3ddbbc632d7e41d9f30e47
MD5 4b6f1c1faeb547319a4b673442104943
BLAKE2b-256 d888cfc47910fb2253715367f6e9a62c26c26b0607e039c35be5e72fcfa41f07

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smpplib-2.2.2-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for smpplib-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 879144778448deee37cb8ec9a18cc39fb7364ddb45b0d6c367134319ffac5e3f
MD5 4f7f03846d577e9f1a5e27f45b408122
BLAKE2b-256 920623680cc3754f14ecdc835b8fdb721cd11e07f902289512564ff12fad9a40

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