Welcome to zipp documentation!

For Enterprise

Professional support for zipp is available as part of the Tidelift Subscription. Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.

Learn more Request a Demo

class zipp.Path(root, at='')

Bases: object

A importlib.resources.abc.Traversable interface for zip files.

Implements many of the features users enjoy from pathlib.Path.

Consider a zip file with this structure:

├── a.txt
└── b
    ├── c.txt
    └── d
        └── e.txt
>>> data = io.BytesIO()
>>> zf = zipfile.ZipFile(data, 'w')
>>> zf.writestr('a.txt', 'content of a')
>>> zf.writestr('b/c.txt', 'content of c')
>>> zf.writestr('b/d/e.txt', 'content of e')
>>> zf.filename = 'mem/abcde.zip'

Path accepts the zipfile object itself or a filename

>>> path = Path(zf)

From there, several path operations are available.

Directory iteration (including the zip file itself):

>>> a, b = path.iterdir()
>>> a
Path('mem/abcde.zip', 'a.txt')
>>> b
Path('mem/abcde.zip', 'b/')

name property:

>>> b.name

join with divide operator:

>>> c = b / 'c.txt'
>>> c
Path('mem/abcde.zip', 'b/c.txt')
>>> c.name

Read text:

>>> c.read_text(encoding='utf-8')
'content of c'


>>> c.exists()
>>> (b / 'missing.txt').exists()

Coercion to string:

>>> import os
>>> str(c).replace(os.sep, posixpath.sep)

At the root, name, filename, and parent resolve to the zipfile.

>>> str(path)
>>> path.name
>>> path.filename == pathlib.Path('mem/abcde.zip')
>>> str(path.parent)

If the zipfile has no filename, such attributes are not valid and accessing them will raise an Exception.

>>> zf.filename = None
>>> path.name
Traceback (most recent call last):
TypeError: ...
>>> path.filename
Traceback (most recent call last):
TypeError: ...
>>> path.parent
Traceback (most recent call last):
TypeError: ...

# workaround python/cpython#106763 >>> pass

property filename

Return whether this path is a symlink.

property name
open(mode='r', *args, pwd=None, **kwargs)

Open this entry as text or binary following the semantics of pathlib.Path.open() by passing arguments through to io.TextIOWrapper().

property parent
read_text(*args, **kwargs)
relative_to(other, *extra)
property stem
property suffix
property suffixes
class zipp.glob.Translator(seps: str = _default_seps)

Bases: object

>>> Translator('xyz')
Traceback (most recent call last):
AssertionError: Invalid separators
>>> Translator('')
Traceback (most recent call last):
AssertionError: Invalid separators

Extend regex for pattern-wide concerns.

Apply ‘(?s:)’ to create a non-matching group that matches newlines (valid on Unix).

Append ‘Z’ to imply fullmatch even when match is used.


Perform the replacements for a match from separate().


Raise ValueError if ** appears in anything but a full path segment.

>>> Translator().translate('**foo')
Traceback (most recent call last):
ValueError: ** must appear alone in a path segment
seps: str

Ensure that * will not match an empty segment.


Given a glob pattern, produce a regex that matches it.


Given a glob pattern, produce a regex that matches it.

>>> t = Translator()
>>> t.translate_core('*.txt').replace('\\\\', '')
>>> t.translate_core('a?txt')
>>> t.translate_core('**/*').replace('\\\\', '')

Separate out character sets to avoid translating their contents.

>>> [m.group(0) for m in separate('*.txt')]
>>> [m.group(0) for m in separate('a[?]txt')]
['a', '[?]', 'txt']

Indices and tables