Send your First SMS with the Telnyx Python SDK
In this guide, messaging engineer Badal Moradia will walk you through sending your first SMS using our Python SDK.
By Michael Bratschi
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 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
python 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
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.
bash python send.py
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.
Take advantage of insights from 1 billion+ messages with our '2023 Guide to SMS and MMS'. Download your copy to learn from Telnyx experts and shape your ideal SMS/MMS strategy.