Send Text Message (SMS) in Python using Fast2SMS

Pratham Anchan
2 min readJun 20, 2018

--

You can send SMS through Python using Fast2SMS Service.

There are many online services which provide API for the sending free SMS like Twilio ,way2sms , Fast2sms etc.

But Twilio has a lot of restrictions in India, because SMS is sent from an International number which is likely to be blocked.

In this example I will describe about sending an SMS from a python code using Fast2SMS API.

  • Sign up to Fast2SMS : Unlimited Free SMS in India
  • You will be assigned with an API authorisation key , which you need to be included in the Python code.
  • You can send 20 free SMS daily. The message is sent with your mobile number as initials.

Test by running the Python code below. Include your API auth key ,message to be sent and also include the mobile number of the recipients( I have considered 9999… , 8888…) . If you are using the Free SMS service than the default sender_id is FSTSMS.

import requestsurl = "https://www.fast2sms.com/dev/bulk"payload = "sender_id=FSTSMS&message=test&language=english&route=p&numbers=9999999999,888888888"headers = {'authorization': "YOUR_AUTH_KEY",'Content-Type': "application/x-www-form-urlencoded",'Cache-Control': "no-cache",}response = requests.request("POST", url, data=payload, headers=headers)print(response.text)

For example If you want to send an “Good Morning” message to a recipients with mobile number 985411279 and 854112799 , then payload in the code changes to

payload = "sender_id=FSTSMS&message=GoodMorning&language=english&route=p&numbers=985411279,854112799"

For more info : docs.fast2sms.com

If you have any problem, let me know

ThankYou

--

--