Skip to content

Repository files navigation

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

importsendlk# Before import any module from sendlk you should initialize it first# secret will use in the OTP/Phone number verify modulesendlk.initialize("sendlk-token", "my-custom-super-secret")
fromsendlk.responsesimportSmsResponse, ProfileResponsefromsendlk.exceptionsimportSendLKExceptionfromsendlk.engineimportSMS, Profilefromsendlk.optionsimportSendLKVerifyOption, SendLKCodeTemplatetry:
response: SmsResponse=SMS.send("07XXXXXXXX", "Hello World!", "SendTest")
print(response)
exceptSendLKExceptionase:
print(e)

Send OTP/Verify Code

importsendlk# Before import any module from sendlk you should initialize it first# secret will use in the OTP/Phone number verify modulesendlk.initialize("sendlk-token", "my-custom-super-secret")
fromsendlk.responsesimportSmsResponsefromsendlk.exceptionsimportSendLKExceptionfromsendlk.engineimportSMSfromsendlk.optionsimportSendLKVerifyOption, 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."classCustomCodeTemplate(SendLKCodeTemplate):
def__init__(self):
super().__init__()
deftext(self, code: str) ->str:
returnf"{code} is the verification code for foo service."options: SendLKVerifyOption=SendLKVerifyOption(
code_length=6, # Length of the codeexpires_in=5, # Time in minutes the code will expiresender_id=SENDER_ID, # Sender IDsubject="foo", # Subject of the tokencode_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)
exceptSendLKExceptionase:
print(e)

Check remaining balance

importsendlk# Before import any module from sendlk you should initialize it first# secret will use in the OTP/Phone number verify modulesendlk.initialize("sendlk-token", "my-custom-super-secret")
fromsendlk.responsesimportSmsResponse, ProfileResponsefromsendlk.exceptionsimportSendLKExceptionfromsendlk.engineimportSMS, Profiletry:
response: ProfileResponse=Profile.balance()
print(response.remaining)
exceptSendLKExceptionase:
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

About

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

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages