Guide to using our Python SDK for SMS
In this guide, messaging engineer Badal Moradia will walk you through sending your first SMS using our Python SDK in just a few minutes:
Step 1: If you haven’t yet, sign up for a free portal account here, otherwise, log into your Mission Control account.
Step 2: In Mission Control, purchase a phone number by navigating to “Numbers” > “Search & Buy Numbers”. Search for a number within the region of your choice. Make sure to check on the SMS feature before hitting search.
Choose the number you’d like, click on “Add to Cart” then go to your cart to purchase.
Step 3: Click on the “Messaging” link on the left navigation, and click on the “Create your first profile” button. Enter a name for the profile and ensure API V2 is selected. Hit save.
Step 4: Go back to the “Numbers” page and associate your phone number with the messaging profile you just created by choosing the profile you just created under the “Messaging Profile” dropdown.
You‘ll be prompted to accept a monthly recurring charge. Click on the “Accept” button.
Your number is now messaging enabled!
Step 5: Click on the “Auth” link on the left navigation, make sure you’re in “Auth V2” then click on the “Create API Key” button.
Note: Make sure to save your API key somewhere safe as this will be the only time you’ll ever get to see it.
Step 6: If you haven’t yet, ensure you have the Telnyx Python SDK already installed. Full documentation can be found here.
Step 7: 1. Create a new file called
send.py and paste in either the SMS code given below. Additional arguments, such as webhook_url and webhook_failover_url can be supplied in the call to telnyx.Message.create.
1 2 3 4 5 6 7 8 9 10 11 12
import telnyx telnyx.api_key = "YOUR_API_KEY" your_telnyx_number = "+13115552368" destination_number = "+13115552367" telnyx.Message.create( from_=your_telnyx_number, to=destination_number, text="Hello, world!", )
Step 8: Paste your API key, your messaging-enabled Telnyx number as the “from_” number. (Note that the parameter ends with an underscore, in order to avoid collision with the python
from keyword.) Be sure to remove any delimiters like dashes or spaces.
Step 9: Replace the the number you’re sending your message to as the “to” number and your message in “text”. Make sure you’re using the full +E.164 formatted number. In the US and Canada, this typically means adding +1 to the beginning of your 10-digit phone number.
Step 9: Run your python script.
Step 10: In a few moments you’ll receive a message at your number on your device. Congrats, you’ve just sent your first SMS!
Now that you've set up your outbound capabilities, you might want to check out our full guide to receiving SMS.
Share on Social