Send SMS using Python msg91-sms PyPI package

MSG91 is a well-known API provider to send SMS. In this tutorial, I am going to show you how to send SMS with MSG91 API using Python msg91-sms PyPI package.

The msg91-sms library is available on PyPI. First of all, you need to install this library. Below is how to install it using pip:

pip install msg91-sms


Requirements for msg91-sms Python library

Keep it in mind that, request and json library are required to use this Python package. So it should be installed in your system.

After the installation of msg91-sms done successfully, you have to import it:

import msg91_sms as msgsms

After that, you can use it to send SMS. In msg91-sms there are already written the class within the package. You just need to create an object of the class:

msg = msgsms.Cspd_msg91(apikey='YOUR MSG91 API KEY')

Now, replace the “YOUR MSG91 API KEY'” with your own MSG91 API key. You can get this API key from official MSG91 site.

Now I am going to discuss how to send SMS.


Send an SMS

To send a custom SMS using MSG91 API key, below is the example code:


In the above code, you have to provide the route, phone number and SMS text. For example, below is the complete code that sends SMS with route 4:

import msg91_sms as msgsms

msg = msgsms.Cspd_msg91(apikey='YOUR MSG91 API KEY')
sms_txt = "This is a text SMS from MSG91"
send_sms_resp = msg.send(4,'TXTIN','919999999999',sms_txt)



Below is the complete code to send OTP SMS:

otp_sms_txt = "Your otp code is ##OTP##"
send_otp_sms_resp = msg.send_otp('TXTIN',919999999999,otp_sms_txt)

The “##OTP##” will contain the OTP code in the SMS text.


Verify OTP

Below is how to verify the OTP received for the phone number:

otp_verify_response = msg.verify_otp(919999999999,OTP_code)


Resend OTP

Below is how to send OTP using Python and msg-91 PyPI package:

resend_otp_sms_resp = msg.resend_otp(919999999999)


I hope, you have understood how to send SMS using Python and MSG91 API with the msg91-sms PyPI library.

Also, read:


4 responses to “Send SMS using Python msg91-sms PyPI package”

  1. M.C. Sai Suhas says:

    How to receive an SMS. Can you
    pleass the code for that

  2. Shivakumar M says:

    Im not able to download this module.
    Can you help mw out with this please?

  3. Shivakumar M says:

    We have alo willing to buy msg91 service please let us know how to download this module.

  4. arul says:

    Even I am facing problem to install the module
    Collecting msg91-sms
    Downloading msg91_sms-1.0.2-py3-none-any.whl (2.9 kB)
    ERROR: Could not find a version that satisfies the requirement json (from msg91-sms) (from versions: none)
    ERROR: No matching distribution found for json (from msg91-sms)

Leave a Reply

Your email address will not be published. Required fields are marked *