A collection of tools to work with SMS messages.
Project description
A collection of tools used to send SMS messages.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sms-toolkit-1.0.9.tar.gz
.
File metadata
- Download URL: sms-toolkit-1.0.9.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc41d2a98e242a481088a26ebfa790c53b00904a24041703af48522e1a8a6c66 |
|
MD5 | 52a2f6f47d6c1f4e215d6032d7be18a2 |
|
BLAKE2b-256 | a590a7fbf7aa49d19f722ef3e37dbba99d305a2ec370f11068cb2cd8cad778b7 |