Are you familiar with Python's tarfile module?

http://docs.python.org/2/library/tarfile.html