gzip is only for compression of a single stream. To maintain the structure of multiple files and directories, you need the tar format, which is usually compressed with gzip. The resulting filename suffix is .tar.gz
.
Use tarfile
in Python, which will handle both the tarring and the gzipping.