---
source: https://iinventedlight.com/library/notes/python-zipimport.md
title: "Python zipimport: load modules from a ZIP archive on sys.path"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, zipimport — Import modules from Zip archives; CPython, zipimport documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-zipimport"
tags: [python, zipimport, import, zip, sys.path]
client: Librarian
sources:
  - id: S1
    title: "zipimport — Import modules from Zip archives"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/zipimport.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "zipimport documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/zipimport.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# Python zipimport: load modules from a ZIP archive on sys.path
**Answer:** zipimport can load Python modules and packages out of a ZIP archive on sys.path.

## How imports find a ZIP file

It is usually not needed to use the zipimport module explicitly.

The built-in import mechanism applies it automatically when a sys.path item is a path to a ZIP file.

The ZIP archive can contain a subdirectory structure to support package imports.

Typically, sys.path is a list of directory names as strings.

This module also allows a sys.path item to name a ZIP file archive.

You can specify a path within the archive, such as example.zip/lib/, to import only from that subtree.

Importers are invoked only for .py and .pyc files. ZIP import of dynamic modules (.pyd, .so) is disallowed.

For an archive that only contains .py files, Python will not attempt to add the corresponding .pyc file into the archive, so importing may be slow.

## The zipimporter API

ZipImportError is raised by zipimporter objects. It is a subclass of ImportError, so it can be caught as ImportError, too.

archivepath must be a path to a ZIP file, or a specific path within a ZIP file such as foo/bar.zip/lib.

ZipImportError is raised if archivepath doesn't point to a valid ZIP archive.

zipimporter is the class for importing ZIP files.

Changed in version 3.15: Zstandard (zstd) compressed zip file entries are supported.

Use find_spec() instead of find_loader() and find_module(), which were deprecated in 3.10 and later removed.

Changed in version 3.8: Previously, ZIP archives with an archive comment were not supported.

Changed in version 3.13: ZIP64 is supported.

## See also

- [python-pkgutil](https://iinventedlight.com/library/notes/python-pkgutil/)
- [python-importlib-resources](https://iinventedlight.com/library/notes/python-importlib-resources/)
- [python-importlib-metadata](https://iinventedlight.com/library/notes/python-importlib-metadata/)

## Claims

- id: C1
  claim: You usually do not need to import zipimport yourself.
  source: S1
  evidence: "It is usually not needed to use the zipimport module explicitly"

- id: C2
  claim: Native extension modules inside a ZIP file are not imported.
  source: S1
  evidence: "ZIP import of dynamic modules"

- id: C3
  claim: The RST synopsis describes support for importing from ZIP archives.
  source: S2
  evidence: "Support for importing Python modules from ZIP archives."

## Sources

- [S1] zipimport — Import modules from Zip archives. Python Software Foundation. https://docs.python.org/3/library/zipimport.html . License: PSF License Version 2. Accessed 2026-11-26.

- [S2] zipimport documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/zipimport.rst . License: PSF License Version 2. Accessed 2026-11-26.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, zipimport — Import modules from Zip archives; CPython, zipimport documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
