from subprocess import Popen, PIPE
import hashlib
proc = Popen(['tar', '-c', '/etc/hosts'], stdout=PIPE)
stdout, stderr = proc.communicate()
hashlib.md5(stdout).hexdigest()
Python - How to call bash commands with pipe?