Registry / serialization / zipfile36

zipfile36

JSON →
library0.1.3pypypi✓ verified 23d ago

zipfile36 is a backport of the `zipfile` module from Python 3.6, offering enhancements and API changes introduced in that version to older Python environments. Its latest version is 0.1.3, released in October 2016. As a backport for an End-of-Life Python version (3.6), the library is considered to be in maintenance status with no active development.

pip install zipfile36
INSTALL
IMPORT
SIG · ZIPFILE36
Z
zipfile36
serializationpythonv0.1.3
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

zipfile
import sys if sys.version_info >= (3, 6): import zipfile else: import zipfile36 as zipfile
import zipfile36
The backport is designed to be aliased as `zipfile` for compatibility with existing code written for the standard library's `zipfile` module. Direct import as `zipfile36` works but deviates from the intended usage pattern.

This quickstart demonstrates how to use `zipfile36` (aliased as `zipfile`) to create a ZIP archive, add a file to it, and then read the file's contents from the archive. It includes the recommended conditional import statement.

import sys import os import io # Suggested usage for zipfile36 backport if sys.version_info >= (3, 6): import zipfile else: try: import zipfile36 as zipfile except ImportError: print("zipfile36 not installed. Please install with 'pip install zipfile36' for Python versions < 3.6.") sys.exit(1) # Create a dummy file file_content = "Hello, zipfile36! This is a test file." file_name = "test_file.txt" with open(file_name, "w") as f: f.write(file_content) zip_file_name = "my_archive.zip" # 1. Create a zip archive and add a file print(f"Creating '{zip_file_name}' and adding '{file_name}'...") with zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED) as zf: zf.write(file_name, arcname="docs/zipped_test_file.txt") print(f"'{file_name}' added to '{zip_file_name}' as 'docs/zipped_test_file.txt'.") # 2. Read from the zip archive print(f"\nReading contents from '{zip_file_name}'...") with zipfile.ZipFile(zip_file_name, 'r') as zf: print(f"Files in '{zip_file_name}': {zf.namelist()}") with zf.open("docs/zipped_test_file.txt") as member_file: read_content = member_file.read().decode('utf-8') print(f"Content of 'docs/zipped_test_file.txt': {read_content}") # Clean up os.remove(file_name) os.remove(zip_file_name) print("\nCleaned up dummy files.")
Debug
Known issues
breakingPickling `zipfile.ZipFile` instances will raise a `TypeError` in Python 3.6+ (and by extension, when using `zipfile36`). This behavior change fixed a prior bug in Python < 3.6 where `ZipFile` objects containing unpicklable `_thread.RLock` objects were incorrectly picklable. Code relying on pickling `ZipFile` objects for serialization will break.
fix
Avoid pickling `zipfile.ZipFile` instances directly. Instead, serialize the necessary file paths or contents and recreate `ZipFile` objects as needed.
affects: 0.1.x on Python >= 3.6 (native `zipfile`), or older Python versions using `zipfile36`.
gotchaThe `zipfile.is_zipfile()` function is not a robust file type identifier and can produce false positives. It primarily checks for the presence of a ZIP central directory signature at the end of a file, which can coincidentally appear in other file types (e.g., gzipped files, executables with appended data).
fix
For reliable file type detection, use dedicated file-sniffing libraries (e.g., `python-magic`, `filetype`) or validate the content more thoroughly after initial checks, especially when dealing with untrusted sources.
affects: All versions of `zipfile36` (and the native `zipfile` module in CPython).
breakingError types for certain operations changed in Python 3.6. Specifically, operations on a closed `ZipFile` (e.g., `open()`, `write()`, `extract()`, `extractall()`, `writestr()`) or with an invalid mode will now raise `ValueError` instead of `RuntimeError`.
fix
Update exception handling blocks to catch `ValueError` instead of `RuntimeError` for operations that misuse `ZipFile` objects (e.g., operating on a closed archive).
affects: 0.1.x, impacts users migrating from Python < 3.6 or expecting `RuntimeError`.
deprecatedThe `mode='U'` option for `ZipFile.open()` (for universal newlines mode) was removed in Python 3.6.
fix
Instead of `mode='U'`, use `io.TextIOWrapper` to read compressed text files with explicit encoding and newline handling. For example: `io.TextIOWrapper(zip_file.open('member.txt'), encoding='utf-8', newline='')`.
affects: 0.1.x, specifically affects usage of `mode='U'`.
Upgrade
Version history
0.1.3latest on PyPI · released Oct 16, 2016
Audit
Dependencies
zliboptionalRequired for DEFLATE compression. Typically built-in with Python, but might be missing in some custom installations.
bz2optionalRequired for BZIP2 compression, if used.
lzmaoptionalRequired for LZMA compression, if used.
compression.zstdoptionalRequired for ZSTD compression, if used (available in newer Python versions).
Agent activity
35 hits · last 30 days
node
30
OpenAI (training)
1
Resources