{"id":7665,"library":"remotezip2","title":"remotezip2","description":"remotezip2 is a Python library that provides efficient access to individual files within a remote ZIP archive without requiring the full download of the entire archive. It functions by leveraging HTTP Range requests, making it suitable for scenarios where only specific contents of large remote ZIP files are needed. As a fork of the original `python-remotezip`, it aims for continued maintenance and responsiveness. The current version is 0.0.2, with a relatively slow release cadence, having received a maintenance update in late 2024 since its initial release.","status":"active","version":"0.0.2","language":"en","source_language":"en","source_url":"https://github.com/doronz88/python-remotezip2","tags":["zip","remote","http","archive","file","network"],"install":[{"cmd":"pip install remotezip2","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used for making HTTP requests, including Range headers, to fetch parts of the remote ZIP file.","package":"requests","optional":false}],"imports":[{"note":"remotezip2 is a distinct package; ensure you import from the correct package name.","wrong":"from remotezip import RemoteZip","symbol":"RemoteZip","correct":"from remotezip2 import RemoteZip"}],"quickstart":{"code":"import os\nfrom remotezip2 import RemoteZip\n\n# Replace with a URL to a real remote ZIP file that supports HTTP Range headers\n# For testing, you can use a publicly available ZIP, e.g., one from thematicmapping.org\nzip_url = os.environ.get('REMOTE_ZIP_URL', 'http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip')\n\ntry:\n    with RemoteZip(zip_url) as rz:\n        print(f\"Files in remote ZIP at {zip_url}:\")\n        for name in rz.namelist():\n            print(f\" - {name}\")\n\n        # Example: Extract a specific file\n        file_to_extract = 'Readme.txt'\n        if file_to_extract in rz.namelist():\n            print(f\"\\nExtracting '{file_to_extract}'...\")\n            with rz.open(file_to_extract) as remote_file:\n                content = remote_file.read().decode('utf-8')\n                print(f\"Content of '{file_to_extract}':\\n---\\n{content[:200]}...\\n---\") # Print first 200 chars\n        else:\n            print(f\"\\nFile '{file_to_extract}' not found in the archive.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure the URL is valid and the server supports HTTP Range requests.\")","lang":"python","description":"This quickstart demonstrates how to list the contents of a remote ZIP file and extract a specific file using `remotezip2`. It initializes `RemoteZip` with a URL and then uses `namelist()` to see the files and `open()` to read the content of a specific member. The `REMOTE_ZIP_URL` environment variable can be used to specify a different ZIP file for testing."},"warnings":[{"fix":"Prefer `extract()` or `open()` for individual files. Only use `extractall()` if the full archive download is acceptable.","message":"The `extractall()` and `testzip()` methods are generally inefficient for remote ZIPs as they necessitate downloading the entire archive. If these operations are frequently needed, a full download might be more efficient.","severity":"gotcha","affected_versions":"All"},{"fix":"Avoid negative seeks when reading individual remote files. If complex random access is required, consider extracting the file locally first.","message":"Performing negative seek operations (e.g., `seek(-offset, 1)`) within a `ZipExtFile` object is highly inefficient, as it typically triggers a new remote request to restart reading from the beginning of the member content.","severity":"gotcha","affected_versions":"All"},{"fix":"Verify that the server hosting the ZIP file supports HTTP Range requests. If not, consider a different approach or server configuration.","message":"The library heavily relies on the remote web server's support for HTTP Range headers to function efficiently. Without this support, the library may fail or resort to full downloads, losing its primary benefit.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure that any remote ZIP files you intend to process with `remotezip2` are well-formed and adhere to modern ZIP file standards to avoid parsing issues, especially those related to central directory and local file header consistency.","message":"As of February 2026, PyPI is enforcing stricter ZIP file validation (e.g., for wheels), rejecting archives with duplicate filenames or invalid `RECORD` metadata. While `remotezip2` consumes ZIPs, not creates them, consuming a malformed ZIP that would now be rejected by PyPI could lead to unexpected behavior or errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change your import statement from `from remotezip import RemoteZip` to `from remotezip2 import RemoteZip`.","cause":"The user is attempting to import from the original `remotezip` package instead of `remotezip2`.","error":"ModuleNotFoundError: No module named 'remotezip'"},{"fix":"Check the server configuration to ensure it supports `Range` headers. Some CDNs or static file servers might disable this. If you control the server, enable Range header support. Otherwise, you might need to download the full file or use a different service.","cause":"The remote server hosting the ZIP file does not support HTTP Range requests, which are essential for `remotezip2` to function by fetching only parts of the file. Or the requested range is invalid.","error":"KeyError: 'Content-length' or `requests.exceptions.HTTPError: 416 Range Not Satisfiable`"},{"fix":"Verify the `zip_url` is correct and points to a legitimate, uncorrupted ZIP archive. Ensure the file itself is a valid ZIP by trying to open it locally.","cause":"The URL provided either does not point to a valid ZIP file, or the initial bytes fetched (e.g., central directory) are corrupted or malformed, preventing the underlying `zipfile` module from recognizing it.","error":"BadZipFile: File is not a zip file"}]}