SMS PDU encoding and decoding, including GSM-0338 character set
SMS PDU encoding and decoding, including GSM-0338 character set.
This library handles SMS-DELIVER and SMS-SUBMIT format PDUs, and includes full support for all data formats, flags and headers, and round-trips from PDU to object and back again.
It also includes convenience APIs for constructing new PDUs from text or data.
This library is very mature - it’s been in production use for many years before the 1.0 release was made. It’s also, as far as I’m aware, the most complete SMS PDU encoding and decoding library available.
The T39 functionality has been copied from the previous PyPI package with the same name as this library to provide some continuity. It is untested.
Typical usage will involve the SMS_SUBMIT and SMS_DELIVER .fromPDU(), .toPDU() and .create() methods:
>>> from smspdu import SMS_SUBMIT >>> pdu = SMS_SUBMIT.create('sender', 'recipient', 'hello, world') >>> pdu.toPDU() '010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C' >>> pdu = smspdu.SMS_SUBMIT.fromPDU(_, 'sender') >>> pdu.user_data u'hello, world'
To decode a PDU on the command-line (using python2.7+), use:
% python -m smspdu 010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C 010010D0F2F2380D4F97DD7400000CE8329BFD6681EE6F399B0C tp_mti = 1 (SMS-SUBMIT) sender = unknown tp_rd = 0 tp_vpf = 0 tp_vp = None tp_rp = 0 tp_udhi = 0 tp_srr = 0 tp_mr = 0 tp_al = 16 tp_toa = d0 (Alphanumeric; Unknown) (recipient) address = 'recipient' tp_pid = 0x00 (Normal Case) tp_dcs = 0x00 (Immedate Display, GSM-0338 Default Alphabet) tp_udl = 12 tp_ud = '\xe82\x9b\xfdf\x81\xeeo9\x9b\x0c' datestamp = 11062712173200 user_data = u'hello, world' user_data_headers = 
The first line re-displays the PDU with the various sections colourised.
Users of versions of Python 2.6 will need to run “python -m smspdu.pdu”.
First the basics; encoding some text:
>>> from smspdu import gsm0338 >>> c = gsm0338() >>> gsm_message = c.encode(u'test message')
And decoding that message:
>>> from smspdu import gsm0338 >>> c = gsm0338() >>> c.decode(gsm_message) u'test message'
The library also provides some functions for making text SMS-happy:
This code is copyright 2011 eKit.com Inc (http://www.ekit.com/) See the end of the source file for the license of use.