Skip to main content

A collection of tools used to send SMS messages.

Test Status

Tools

Message Profiling

Accepts a raw SMS message string and determines its most efficient encoding, then determines how many segments would be used to send it.

Largely based on this tool (code found here).

The segmenting logic for GSM-7 and UCS-2 encoding follows these standards

Here is an example with simple ascii input, which will be profiled as GSM-7 format:

from sms_toolkit.messages.profiling import profile_message
profile_message("Sup chonus")

'''
# Outputs -
{
   "num_segments": 1,
   "segments": [
       {
           "message": "Sup chonus",
           "total_segment_length": 10,
           "unicode_character_list": [
               "S", "u", "p", " ", "c", "h", "o", "n", "u", "s"
           ],
           "byte_groups": [
               [83], [117], [112], [32], [99], [104], [111], [110], [117], [115]
           ]
       }
   ],
   "message_length": 10,
   "max_segment_size": 160
}
'''

Here is an example with non-ascii input, containing characters from BMP (represented as 2 bytes byte-group) and non-BMP (representing as 4 bytes in the byte-group) ranges which will be profiled as UCS-2 format:

from sms_toolkit.messages.profiling import profile_message
profile_message("fuel ⛽ fiⓇe 🔥 emojis 😉")

'''
# Outputs -
{
    'num_segments': 1,
    'segments': [
        {
            'message': 'fuel ⛽ fiⓇe 🔥 emojis 😉',
            'unicode_character_list': [
                'f', 'u', 'e', 'l', ' ', '⛽', ' ', 'f', 'i', 'Ⓡ', 'e', ' ', '🔥', ' ', 'e', 'm', 'o', 'j', 'i', 's', ' ', '😉'
            ],
            'byte_groups': [
                [0, 102], [0, 117], [0, 101], [0, 108], [0, 32], [38, 253], [0, 32], [0, 102], [0, 105], [36, 199], [0, 101], [0, 32], [216, 61, 221, 37], [0, 32], [0, 101], [0, 109], [0, 111], [0, 106], [0, 105], [0, 115], [0, 32], [216, 61, 222, 9]
            ],
            'total_segment_length': 24
        }
    ],
    'message_length': 24,
    'max_segment_size': 70
}
'''

Message Truncating

Accepts a raw SMS message string, and the maximum length and truncates it. This also detects the right encoding and adjusts the character length accordingly.

from sms_toolkit import truncate_message
truncate_message("fuel ⛽ fiⓇe 🔥 emojis 😉", 22)

'''
# Outputs -
'fuel ⛽ fiⓇe 🔥 emojis '
'''

Testing

This library needs is tested against python 2 and 3. Both interpreters need to be available to tox

pyenv versions  # shows all versions available
pyenv local 2.7.* 3.7.*

Run tests:

tox .

Acknowledgements

Klaviyo has adapted the original vobject packaged in to this package. We have only kept the vcard class from the original package, removing calendar functionality, etc.

Release files for sms-toolkit 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sms-toolkit 1.0.9
File Size Uploaded
sms-toolkit-1.0.9.tar.gz 25.3 kB Details

Release files / sms-toolkit-1.0.9.tar.gz

Download URL sms-toolkit-1.0.9.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bc41d2a98e242a481088a26ebfa790c53b00904a24041703af48522e1a8a6c66
BLAKE2b-256 checksum
How to use checksums
a590a7fbf7aa49d19f722ef3e37dbba99d305a2ec370f11068cb2cd8cad778b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.8.2 requests/2.27.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/2.7.15

Release history Release notifications | RSS feed

This release

1.0.9 This release

1 release file

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page