pydoc > tarfile

πŸ“› NAME

tarfile - Read from and write to tar format archives.

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ“¦ Open tar for readingtarfile.open("archive.tar")Open with transparent compression detection
πŸ“¦ Open tar for writingtarfile.open("archive.tar", "w")Create a new uncompressed tar (overwrites)
πŸ“¦ Open tar for appendingtarfile.open("archive.tar", "a")Append to an existing archive
πŸ—œοΈ Open compressed tartarfile.open("archive.tar.gz", "r:gz")Read gzip-compressed tar
πŸ” List memberstar.getmembers()Returns list of TarInfo objects
πŸ“‹ List namestar.getnames()Returns list of member names
πŸ“„ Extract single filetar.extract("file.txt")Extract to current directory
πŸ“‚ Extract all filestar.extractall()Extract entire archive
βž• Add filetar.add("myfile")Add a file or directory recursively
πŸ”Ž Check if tartarfile.is_tarfile("archive")Returns True if it's a valid tar

πŸ“š 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

builtins.Exception(builtins.BaseException)
    TarError
        CompressionError
        ExtractError
        HeaderError
        ReadError
        StreamError
builtins.object
    TarFile
    TarInfo

🧩 class CompressionError(TarError)

Exception for unavailable compression methods.

Inherits from TarError β†’ builtins.Exception β†’ builtins.BaseException β†’ builtins.object.

Data descriptors inherited from TarError:

Standard exception methods (__init__, __new__, __repr__, __str__, etc.) inherited from builtins.Exception and builtins.BaseException.

🧩 class ExtractError(TarError)

General exception for extract errors.

Inherits from TarError β†’ builtins.Exception β†’ builtins.BaseException β†’ builtins.object.

Data descriptors inherited from TarError:

Standard exception methods inherited.

🧩 class HeaderError(TarError)

Base exception for header errors.

Inherits from TarError β†’ builtins.Exception β†’ builtins.BaseException β†’ builtins.object.

Data descriptors inherited from TarError:

Standard exception methods inherited.

🧩 class ReadError(TarError)

Exception for unreadable tar archives.

Inherits from TarError β†’ builtins.Exception β†’ builtins.BaseException β†’ builtins.object.

Data descriptors inherited from TarError:

Standard exception methods inherited.

🧩 class StreamError(TarError)

Exception for unsupported operations on stream-like TarFiles.

Inherits from TarError β†’ builtins.Exception β†’ builtins.BaseException β†’ builtins.object.

Data descriptors inherited from TarError:

Standard exception methods inherited.

🧩 class TarError(builtins.Exception)

Base exception.

Inherits from builtins.Exception β†’ builtins.BaseException β†’ builtins.object.

Data descriptors defined here:

Standard exception methods inherited.

πŸ“¦ class TarFile(builtins.object)

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 defined here:

⭐ Class methods:

πŸ“Š Data descriptors:

πŸ“Œ Data and other attributes:

OPEN_METH = {'bz2': 'bz2open', 'gz': 'gzopen', 'tar': 'taropen', 'xz':...}

πŸ“‹ class TarInfo(builtins.object)

TarInfo(name='')

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

πŸ”§ Methods defined here:

⭐ 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:
'r' or 'r:*' open for reading with transparent compression
'r:'         open for reading exclusively uncompressed
'r:gz'       open for reading with gzip compression
'r:bz2'      open for reading with bzip2 compression
'r:xz'       open for reading with lzma compression
'a' or 'a:'  open for appending, creating the file if necessary
'w' or 'w:'  open for writing without compression
'w:gz'       open for writing with gzip compression
'w:bz2'      open for writing with bzip2 compression
'w:xz'       open for writing with lzma compression

'x' or 'x:'  create a tarfile exclusively without compression, raise
             an exception if the file is already created
'x:gz'       create a gzip compressed tarfile, raise an exception
             if the file is already created
'x:bz2'      create a bzip2 compressed tarfile, raise an exception
             if the file is already created
'x:xz'       create an lzma compressed tarfile, raise an exception
             if the file is already created

'r|*'        open a stream of tar blocks with transparent compression
'r|'         open an uncompressed stream of tar blocks for reading
'r|gz'       open a gzip compressed stream of tar blocks
'r|bz2'      open a bzip2 compressed stream of tar blocks
'r|xz'       open an lzma compressed stream of tar blocks
'w|'         open an uncompressed stream for writing
'w|gz'       open a gzip compressed stream for writing
'w|bz2'      open a bzip2 compressed stream for writing
'w|xz'       open an lzma compressed stream for writing

πŸ“Š DATA

DEFAULT_FORMAT = 2
ENCODING = 'utf-8'
GNU_FORMAT = 1
PAX_FORMAT = 2
USTAR_FORMAT = 0
__all__ = ['TarFile', 'TarInfo', 'is_tarfile', 'TarError', 'ReadError'...

✍️ 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
🧩 class CompressionError(TarError) 🧩 class ExtractError(TarError) 🧩 class HeaderError(TarError) 🧩 class ReadError(TarError) 🧩 class StreamError(TarError) 🧩 class TarError(builtins.Exception) πŸ“¦ class TarFile(builtins.object) πŸ“‹ class TarInfo(builtins.object)
⚑ FUNCTIONS
is_tarfile(name) open(name=None, mode='r', fileobj=None, bufsize=10240, **kwargs)
πŸ“Š DATA ✍️ AUTHOR πŸ™ CREDITS πŸ“ FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 11:10 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^