Python tarfile Module
Example
Create an in-memory tar archive:
import tarfile
import io
buffer = io.BytesIO()
with tarfile.open(fileobj=buffer, mode='w') as tar:
print('Tar archive created in memory')
print(f'Format: {tar.format}')
Try it Yourself »
Definition and Usage
The tarfile module reads and writes tar archives, including compressed formats like gzip, bz2, and xz.
Use it to create, extract, or manipulate tar archives, a common format for file distribution and backups.
Members
Member | Description |
---|---|
TarError | Base exception for tarfile errors. |
TarFile | Class for reading and writing tar archives. |
TarInfo | Class representing a member of a tar archive. |
is_tarfile() | Return True if name points to a valid tar archive. |
open() | Open a tar archive for reading or writing. |