There are three steps to integrating our programmable SMS API into your Python project.
1. Create an account.
Sign up for an Esendex account. When you register you will receive a license key. You will need this to use the API.
2. Install Python.
Install Python if it is not on your computer already. To check, run this command in your terminal: python --version
PS C:> python --version
Python 3.11.0
Next, make sure you have pip (the Python package installer). This is usually included when you install Python, but you can install pip separately here. To check, run this command in your terminal: python -m pip --version
PS C:> python -m pip --version
pip 22.3 from C:Python311Libsite-packagespip (python 3.11)
3. Send a test message.
Install httpx, an HTTP client library for Python. Run this command in your terminal: pip install httpx
Create a new Python file. Let’s call it demo.py.
You can use the SendMessage
method to send a text message. Add the displayed code to your new file.
Replace the LicenseKey
value with your account’s license key.
Replace the To
value with your own mobile phone number.
import httpx
headers = {"Accept": "application/json"}
url = "https://messaging.esendex.us/Messaging.svc/SendMessage"
request = {
"Body": "Hi, this message was sent using Python.",
"LicenseKey": "00000000-0000-0000-0000-000000000000",
"To": ["7575559999"],
"UseMMS": False,
}
with httpx.Client(headers=headers) as client:
response = client.post(url=url, json=request)
response.raise_for_status()
message = response.json()[0]
print(f"Message status: {message['MessageStatus']}")
Run the project in your terminal with this command: python demo.py
. If the message status is 201 (the code for Ready), your call to the API was a success! You will receive the text message shortly on your phone.
PS C:PythonDemo> python demo.py
Message status: 201