---slug: /guides/how-to-get-reply-statistics-with-pythonsidebar_position: 20x-custom: ported_from_readme: true needs_review: true---# Reply StatisticsThis guide will use the SignalWire Python SDK to get a list of owned DIDs, and compare inbound and outbound messages to provide statistics on reply rate.The resulting stats.## What do I need to run this?You will only need the [SignalWire Python SDK](pathname:///compatibility-api/rest/overview/client-libraries-and-sdks/#python), and your SignalWire API credentials. If you arent sure where to find your credentials, check out [this](/guides/navigating-your-space) guide on naviating your space.## How do I run this code?### Check out the full codeFull code example: Get reply statistics for SMSpythonfrom signalwire.rest import Client as signalwire_clientSIGNALWIRE_PROJECT_KEY =SIGNALWIRE_TOKEN = SIGNALWIRE_SPACE = client = signalwire_client(SIGNALWIRE_PROJECT_KEY, SIGNALWIRE_TOKEN, signalwire_space_url=SIGNALWIRE_SPACE)replydict={}uniquereplies=[]ournumbers=[]badsmsbody=[STOP,NO,UNSUBSCRIBE]badsmsnumbers=[]sentmsgscount = 0response = client.incoming_phone_numbers.list()for sid in response: ournumbers.append(sid.phone_number)response = client.messages.list()for message in response: if message.from_ in ournumbers: sentmsgscount = sentmsgscount+1 if message.body in badsmsbody: badsmsnumbers.append(message.from_) if message.from_ not in ournumbers and message.to in ournumbers: if message.body not in badsmsbody and message.from_ not in uniquereplies: uniquereplies.append(message.from_) replydict[message.sid] = [message.from_,message.body]replycount = len(replydict)uniquecount = len(uniquereplies)badcount = len(badsmsnumbers)replypercent = (replycount/sentmsgscount)*100sentmsgscount = str(sentmsgscount)print (You sent +str(sentmsgscount)+ messages)print(You recieved + str(replycount) + Replies)print(str(uniquecount) + Unique User Replied)print(str(badcount)+ Stop or other bad replies)print(Your reply rate is + str(replypercent)+ %)### Run NativelyRun the app.py file in your python environment of choice.## Code WalkthroughThe only file for this snippet will be an app.py file.### Into our application#### SetupFirst we will import our SignalWire python SDK to handle our requests to SignalWire.pythonfrom signalwire.rest import Client as signalwire_clientNow we can use our SignalWire credentials to create a clientpythonclient = signalwire_client(SIGNALWIRE_PROJECT_KEY, SIGNALWIRE_TOKEN, signalwire_space_url=SIGNALWIRE_SPACE)Setting up our lists and dictionary variables for later use.replydict will take each message with the message SID as the key, and the message from_ and body as a list of values.uniqureplies will be our filtered good replies listournumbers will pull numbers from our project. this could be replaced with a list of phone numbers from a campaign to create a more granular overview of an account with multiple campaigns.badsmsbody is our list of bad words, these could be opt-out phrases, or any other replies you do not want to consider useful to count in your statisticsbadsmsnumbers is a list of the phone numbers who have sent bad replies.sentmsgcount will count the the outbound messages sent from ournumberspythonreplydict={}uniquereplies=[]ournumbers=[]badsmsbody=[STOP,NO,UNSUBSCRIBE]badsmsnumbers=[]sentmsgscount = 0#### List ournumbersNow that we are done with our setup we can begin by populating our list of phone numbers.pythonresponse = client.incoming_phone_numbers.list()for sid in response: ournumbers.append(sid.phone_number)#### List messagesThen we can call a list of all messages. You could filter these messages by passing arguments to client.messages.list().For each message we get from this call, we will check if the message is from one of ournumbers and increment sentmsgscountThen we will check the message body and append bad messages to our badsmsnumbers list.Then, if the message is not from ournumbers, and is to ournumbers. We ensure that the message is not bad, and is a unique entry to our uniquereplies list. Additionally we will add all replies regardless of if they are unique to our replydict.pythonresponse = client.messages.list()for message in response: if message.from_ in ournumbers: sentmsgscount = sentmsgscount+1 if message.body in badsmsbody and message.from_ not in ournumbers: badsmsnumbers.append(message.from_) if message.from_ not in ournumbers and message.to in ournumbers: if message.body not in badsmsbody and message.from_ not in uniquereplies: uniquereplies.append(message.from_) replydict[message.sid] = [message.from_,message.body]#### Data formattingFinally, we will do some calculations, and format our data so it can be printed to the console.pythonreplycount = len(replydict)uniquecount = len(uniquereplies)badcount = len(badsmsnumbers)replypercent = (replycount/sentmsgscount)*100sentmsgscount = str(sentmsgscount)print (You sent +str(sentmsgscount)+ messages)print(You recieved + str(replycount) + Replies)print(str(uniquecount) + Unique User Replied)print(str(badcount)+ Stop or other bad replies)print(Your reply rate is + str(replypercent)+ %)An example of output would be printed to the console like so:outputYou sent 60 messagesYou recieved 11 Replies1 Unique User Replied0 Stop or other bad repliesYour reply rate is 18.333333333333332%## WrapupThis guide provides a basic application to gather statistics on sms replies using the SignalWire python SDK. While this is a basic implementation it can be a powerful tool to implement into more in-depth reporting systems for your SignalWire usage.### Resources[Python SignalWire SDK](pathname:///compatibility-api/rest/overview/client-libraries-and-sdks/#python)## Sign Up HereIf you would like to test this example out, you can create a SignalWire account and space [here](https://m.signalwire.com/signups/new?s=1).Please feel free to reach out to us on our [Community Slack](https://signalwire.community/) or create a Support ticket if you need guidance!