I came across lots of people asking how to retrieve the Sender's number from a received SMS in Python even if the contact is in your contacts database.
Here is a quick fix:
Incorporate this to your code to be able to get the number.
# Contact Number from Contacts dB
# XenoArts - John Robert Planta
import contacts #import contact db
db = contacts.open() #store in a variable "db"
found = db.find(sms_sender) #find in database the contact name
try: found #check if found
senderData = found
senderNum = senderData.find("mobile_number").value
senderNum = sms_sender
#now all you have to do is assign a variable the number of that contact name
mobileNum = getSenderNum(contactName)
#change contactName to whatever variable you stored your ripped contact