You can use psutil or psmem with subprocess example code
import subprocess
cmd = subprocess.Popen(['sudo','./ps_mem'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out,error = cmd.communicate()
memory = out.splitlines()
Reference http://techarena51.com/index.php/how-to-install-python-3-and-flask-on-linux/