--stdout
option to git format-patch
the complete Python expression should be like: var = subprocess.check_output(["git", "format-patch", "--stdout", <tree-ish arguments...>])
Also you may consider using GitPython if you need extensive git repo manipulations