pydoc > tarfile

πŸ“– NAME

tarfile β€” Read from and write to tar format archives.

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ“‚ Open tar archive for reading (auto-detect compression)tarfile.open('archive.tar.gz', 'r')Opens with transparent compression; returns a TarFile object.
πŸ“¦ Open tar for writing with gzip compressiontarfile.open('archive.tar.gz', 'w:gz')Creates a new gzip-compressed tar archive.
βž• Add a file to an archivetar.add('file.txt')Adds file.txt to the open TarFile.
πŸ“€ Extract all members to current directorytar.extractall()Extracts all files, preserving metadata.
πŸ“‹ List contents (table of files)tar.list()Prints an ls -l-style listing of archive members.
πŸ” Check if a file is a tar archivetarfile.is_tarfile('file')Returns True if the file is a supported tar archive.
πŸ“„ Get a single member as a file objecttar.extractfile('member')Returns an io.BufferedReader for regular files.

πŸ”— MODULE REFERENCE

https://docs.python.org/3.10/library/tarfile.html

The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.

πŸ“š CLASSES

πŸ› Exception Classes (all inherit from TarError)

All exception classes share the same method resolution order (TarError β†’ builtins.Exception β†’ builtins.BaseException β†’ builtins.object) and inherit the following methods and data descriptors (listed once for TarError):

CompressionError

Exception for unavailable compression methods.

ExtractError

General exception for extract errors.

HeaderError

Base exception for header errors.

ReadError

Exception for unreadable tar archives.

StreamError

Exception for unsupported operations on stream-like TarFiles.

πŸ“¦ TarFile class

TarFile(name=None, mode='r', fileobj=None, format=None, tarinfo=None, dereference=None, ignore_zeros=None, encoding=None, errors='surrogateescape', pax_headers=None, debug=None, errorlevel=None, copybufsize=None)

The TarFile Class provides an interface to tar archives.

Methods

Class Methods

Data Descriptors

Data and Other Attributes

ℹ️ TarInfo class

TarInfo(name='')

Informational class which holds the details about an archive member given by a tar header block. Objects are returned by TarFile.getmember(), TarFile.getmembers() and TarFile.gettarinfo().

Methods

Class Methods

Data Descriptors

πŸ› οΈ FUNCTIONS

is_tarfile(name)

Return True if name points to a tar archive that we are able to handle, else return False. name should be a string, file, or file-like object.

open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)

Open a tar archive for reading, writing or appending. Return an appropriate TarFile class.

Mode descriptions:

πŸ“Š DATA

πŸ‘€ AUTHOR

Lars GustΓ€bel (lars AT gustaebel.de)

πŸ“ CREDITS

Gustavo Niemeyer, Niels GustΓ€bel, Richard Townsend.

πŸ“ FILE

/usr/lib/python3.10/tarfile.py

tarfile
πŸ“– NAME πŸš€ Quick Reference πŸ”— MODULE REFERENCE πŸ“š CLASSES
πŸ› Exception Classes (all inherit from TarError) πŸ“¦ TarFile class ℹ️ TarInfo class
πŸ› οΈ FUNCTIONS
is_tarfile(name) open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)
πŸ“Š DATA πŸ‘€ AUTHOR πŸ“ CREDITS πŸ“ FILE

Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-01 16:56 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^