Skip to main content

A python sdk for the smsdrop.net platform

Project description

Smsdrop-Python

MIT License

The official python sdk for the smsdrop api.

Quickstart

import datetime
import logging
import time

import pytz
from dotenv import dotenv_values

from smsdrop import CampaignCreate, Client, RedisStorage

# Enable Debug Logging
# This will og the API request and response data to the console:
logging.basicConfig(level=logging.DEBUG, format="%(message)s")

config = dotenv_values(".env")

TEST_EMAIL = config.get("TEST_EMAIL")
TEST_PASSWORD = config.get("TEST_PASSWORD")
MY_TIMEZONE = config.get("MY_TIMEZONE")


def main():
    # Initialize the client
    client = Client(
        email=TEST_EMAIL, password=TEST_PASSWORD, storage=RedisStorage()
    )
    # Get your account profile informations
    print(client.read_me())
    # Get your subscription informations
    print(client.read_subscription())
    # Get your first 500 campaigns
    print(client.read_campaigns(skip=0, limit=500))

    # Send a simple sms
    client.send_message(message="hi", sender="Max", phone="<phone>")

    # Create a new Campaign
    cp = CampaignCreate(
        title="Test Campaign",
        message="Test campaign content",
        sender="TestUser",
        recipient_list=["<phone1>", "<phone2>", "<phone3>"],
    )
    cp = client.launch_campaign(cp)
    time.sleep(20)  # wait for 20 seconds for the campaign to proceed
    cp = client.read_campaign(cp.id)  # refresh your campaign data
    print(cp.status)  # Output Example : COMPLETED

    # create a scheduled campaign
    naive_dispatch_date = datetime.datetime.now() + datetime.timedelta(hours=1)
    aware_dispatch_date = pytz.timezone(MY_TIMEZONE).localize(
        naive_dispatch_date
    )
    cp2 = CampaignCreate(
        title="Test Campaign 2",
        message="Test campaign content 2",
        sender="TestUser",
        recipient_list=["<phone1>", "<phone2>", "<phone3>"],
        # The date will automatically be send in isoformat with the timezone data
        defer_until=aware_dispatch_date,
    )
    cp2 = client.launch_campaign(cp2)
    # If you check the status one hour from now it should return 'COMPLETED'

    # create another scheduled campaign using defer_by
    cp3 = CampaignCreate(
        title="Test Campaign 3",
        message="Test campaign content 3",
        sender="TestUser",
        recipient_list=["<phone1>", "<phone2>", "<phone3>"],
        defer_by=120,
    )
    cp3 = client.launch_campaign(cp3)
    time.sleep(120)  # wait for 120 seconds for the campaign to proceed
    cp3 = client.read_campaign(cp3.id)  # refresh your campaign data
    print(cp3.status)  # should output : COMPLETED
    # If you get a 'SCHEDULED' printed, you can wait 10 more seconds in case the network
    # is a little slow or the server is busy


if __name__ == "__main__":
    main()

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

smsdrop-python-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

smsdrop_python-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file smsdrop-python-0.1.0.tar.gz.

File metadata

  • Download URL: smsdrop-python-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.6 Linux/5.11.0-7614-generic

File hashes

Hashes for smsdrop-python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 43de5f973cce37ab9878438593076ad6362e7a16cff5517a662ed379fb5cb7a7
MD5 aba4813d8fb3904caca36e01d4cdc4e1
BLAKE2b-256 cf6579c6369d0e4fa88b2f8b28d411e192ffe758fc8e2baa36845252ab6a048f

See more details on using hashes here.

File details

Details for the file smsdrop_python-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: smsdrop_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.6 Linux/5.11.0-7614-generic

File hashes

Hashes for smsdrop_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f0a9f46761cf20287121aa512004e1c7cc47869f37ad075303a0cc9170b97ec
MD5 74980d31d97ed9dc6b31de3cf0cc0671
BLAKE2b-256 69aff8730a1404416ef2d2ffc4a81715af1d81fcf30911409c95539c7d8559df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page