This is (part of) a PyYYC talk about Git and its internals; see Andrew's repository for the "talk" portion -- this is a demo of using "dulwich" to do low-level (and high-level) Git things.
More about Dulwich:
Andrew's talk:
Install:
pip install dulwich
or (if using Python3):
pip install https://github.com/dulwich/dulwich/archive/master.zip