Skip to main content

Send.lk Python SDK

sendlk is a python SDK for the send.lk SMS getaway.

Example

Here is an article of example, How to use this package with FastAPI -> ishanga.hashnode.dev

Installation

Use the package manager pip to install sendlk.

pip install sendlk

Features

  • Send Messages
  • Send Verify Code (Package's feature)
  • Validate Verify Code (Package's feature)
  • Check Balance
  • TODO: Contacts
  • TODO: Message History

Send Normal SMS

import sendlk

# Before import any module from sendlk you should initialize it first
# secret will use in the OTP/Phone number verify module
sendlk.initialize("sendlk-token", "my-custom-super-secret")

from sendlk.responses import SmsResponse, ProfileResponse
from sendlk.exceptions import SendLKException
from sendlk.engine import SMS, Profile
from sendlk.options import SendLKVerifyOption, SendLKCodeTemplate

try:
    response: SmsResponse = SMS.send("07XXXXXXXX", "Hello World!", "SendTest")
    print(response)
except SendLKException as e:
    print(e)

Send OTP/Verify Code

import sendlk

# Before import any module from sendlk you should initialize it first
# secret will use in the OTP/Phone number verify module
sendlk.initialize("sendlk-token", "my-custom-super-secret")

from sendlk.responses import SmsResponse
from sendlk.exceptions import SendLKException
from sendlk.engine import SMS
from sendlk.options import SendLKVerifyOption, SendLKCodeTemplate

# If you want to use custom text/body you can create custom template using "SendLKCodeTemplate"
# If code text template not given default one will be used
# Default: "0000 is your verification code."
class CustomCodeTemplate(SendLKCodeTemplate):
    def __init__(self):
        super().__init__()
        
    def text(self, code: str) -> str:
        return f"{code} is the verification code for foo service."
    
options: SendLKVerifyOption = SendLKVerifyOption(
    code_length=6, # Length of the code
    expires_in=5, # Time in minutes the code will expire
    sender_id=SENDER_ID, # Sender ID
    subject="foo", # Subject of the token
    code_template=CustomCodeTemplate() # Custom code template
)

try:
    response: SmsResponse = SMS.send_verify_code(PHONE_NUMBER, options)
    token = response.data.get("token", None)
    code = input("Enter the code: ")
    response: SmsResponse = SMS.validate_verify_code(code, token)
    print(response)
    print(response.data)
except SendLKException as e:
    print(e)

Check remaining balance

import sendlk

# Before import any module from sendlk you should initialize it first
# secret will use in the OTP/Phone number verify module
sendlk.initialize("sendlk-token", "my-custom-super-secret")

from sendlk.responses import SmsResponse, ProfileResponse
from sendlk.exceptions import SendLKException
from sendlk.engine import SMS, Profile

try:
    response: ProfileResponse = Profile.balance()
    print(response.remaining)
except SendLKException as e:
    print(e)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Metadata

Release files for sendlk 0.2.0

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

Source distribution (sdist)

Source distribution for sendlk 0.2.0
File Size Uploaded
sendlk-0.2.0.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sendlk 0.2.0
File Interpreter ABI Platform
sendlk-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.5 kB

Release files / sendlk-0.2.0.tar.gz

Download URL sendlk-0.2.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dfb9f6b28990079e2beefded815b8a0d0d1760426befa729cc0f128cd1f80952
BLAKE2b-256 checksum
How to use checksums
11a4e4862b27d459254f8bcb45a0e683c93a12f072021d27ef4f7507630914ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / sendlk-0.2.0-py3-none-any.whl

Download URL sendlk-0.2.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31f6761bcbeff98917fa46481476000077d9a41e9214c35b4388447bd036975b
BLAKE2b-256 checksum
How to use checksums
77178bbf1c85d2d8479b385b9182d19c44475eeed05f22fc0214d309edec5e34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

1 release file

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