When I invoke add() on a tarfile object with a file path, the file is added to the tarball with directory hierarchy associated. In other words, if
add()
tarfile
Maybe you can use the "arcname" argument to TarFile.add(name, arcname). It takes an alternate name that the file will have inside the archive.