Skip to main content

Python SMS PDU Decoder

Project description

SMS-PDU Decoder

PyPI version

This library will help you to decode raw SMS data you can get from a GSM modem (generally by using AT commands).

It has some encoding primitives as well, but full encoding support is not available, since this is not the main purpose of this library.

It is recommended to read the GSM 03.40 specification to better understand the components this library works wtih.

How to install

This library has been successfully tested and works with Python versions ranging from 3.7 up to 3.10.

pip install smspdudecoder

How to use

Please take a look at the source code, which comes with documentation and examples.

For instance, if you need to work with text, you can use GSM and UCS2 encodings just like that:

>>> from smspdudecoder.codecs import GSM, UCS2
>>> GSM.decode('C8F71D14969741F977FD07')
'How are you?'
>>> UCS2.decode('004C006F00720065006D00200049007000730075006D')
'Lorem Ipsum'

If you need to decode a full incoming SMS PDU, you can use the SMSDeliver class:

from io import StringIO
from smspdudecoder.fields import SMSDeliver

deliver_pdu = StringIO('07916407058099F9040B916407950303F100008921222140140004D4E2940A')
sms_data = SMSDeliver.decode(deliver_pdu)

If you execute this example, the sms_data variable will contain a dictionary with the following data:

{
  'smsc': {
    'length': 7,
    'toa': {
      'ton': 'international', 'npi': 'isdn'
    },
    'number': '46705008999'
  },
  'header': {
    'rp': False,
    'udhi': False,
    'sri': False,
    'lp': False,
    'mms': True,
    'mti': 'deliver'
  },
  'sender': {
    'length': 11,
    'toa': { 'ton': 'international', 'npi': 'isdn' },
    'number': '46705930301'
  },
  'pid': 0,
  'dcs': { 'encoding': 'gsm' },
  'scts': datetime.datetime(2098, 12, 22, 12, 4, 41, tzinfo = datetime.timezone.utc),
  'user_data': { 'header': None, 'data': 'TEST' }
}

If you don't need all the technical details, you can use the easy module to get a simple representation of the SMS:

from smspdudecoder.easy import read_incoming_sms

sms = read_incoming_sms('07916407058099F9040B916407950303F100008921222140140004D4E2940A')

Which will produce the following result:

{
  'sender': '+46705930301',
  'content': 'TEST',
  'date': datetime.datetime(2098, 12, 22, 12, 4, 41, tzinfo=datetime.timezone.utc),
  'partial': False
}

How to test and contribute

First, clone this repository:

git clone git@github.com:qotto/smspdudecoder.git
# or use HTTPS if you are unauthenticated:
# git clone https://github.com/qotto/smspdudecoder.git
cd smspdudecoder

Using Docker

The easiest way to test this library against all supported Python versions is to use Docker.

make docker-test

Behinds the scenes, this will build a Docker image with all supported Python versions and run the tests with tox.

Using your existing Python installation

If you want to simply run the test suite, make sure that you have dependencies installed with:

pip install -r requirements.txt

And use the following command:

make test

Project details


Download files

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

Source Distribution

smspdudecoder-2.2.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

smspdudecoder-2.2.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file smspdudecoder-2.2.0.tar.gz.

File metadata

  • Download URL: smspdudecoder-2.2.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for smspdudecoder-2.2.0.tar.gz
Algorithm Hash digest
SHA256 838ca4ecd2c624801d10a097b34efa11a9da95186ca795f3a5cd5ae2bb07c170
MD5 de78c64730f4f9e161954aaf8e7c48f5
BLAKE2b-256 25b987fd990cda47f2787787983ab127bd0ce980045d0c3b5cd61672e215a48e

See more details on using hashes here.

File details

Details for the file smspdudecoder-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: smspdudecoder-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for smspdudecoder-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 087a8ba9b01d452bc457cf3df41d758f683215b0ee71017f5d1b0ee95d2517ce
MD5 446d1070e17795220cbdea835a3aa0f6
BLAKE2b-256 fbd41a621b7e633f874d805ff49de0547b27145e35dbfb09bca67ae1427257c2

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