{"library":"stream-zip","title":"Stream ZIP","type":"library","description":"Stream-zip is a Python library designed to construct ZIP archives on the fly without requiring the entire archive or its constituent files to be held in memory or on disk. This makes it particularly suitable for memory-constrained environments or generating ZIP files for streaming HTTP responses in web servers. It offers both synchronous and asynchronous interfaces and is currently at version 0.0.84, with frequent minor updates.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install stream-zip"],"cli":null},"imports":["from stream_zip import stream_zip","from stream_zip import ZIP_32","from stream_zip import async_stream_zip"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/uktrade/stream-zip","docs":"https://stream-zip.docs.trade.gov.uk/","changelog":null,"pypi":"https://pypi.org/project/stream-zip/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"from datetime import datetime\nfrom stat import S_IFREG\nfrom stream_zip import ZIP_32, stream_zip, ZIP_64\n\ndef generate_file_content(data):\n    yield data.encode('utf-8')\n\ndef member_files():\n    modified_at = datetime.now()\n    mode = S_IFREG | 0o600 # Regular file, owner read/write\n\n    # Example 1: Small file using ZIP_32 (default)\n    yield (\n        'my-file-1.txt',\n        modified_at,\n        mode,\n        ZIP_32,\n        generate_file_content('This is some content for file 1.')\n    )\n\n    # Example 2: Potentially larger file or for explicit 64-bit support\n    yield (\n        'my-file-2.json',\n        modified_at,\n        mode,\n        ZIP_64,\n        generate_file_content('{\"key\": \"value\", \"data\": [1, 2, 3]}')\n    )\n\n    # Example 3: An empty directory\n    yield (\n        'my-directory/',\n        modified_at,\n        S_IFREG | 0o755, # Directory permissions\n        ZIP_32,\n        ()\n    )\n\n# Stream the ZIP file chunks\nzipped_chunks = stream_zip(member_files())\n\n# In a real application, you would send these chunks directly as an HTTP response\n# or write them to a file. For this example, we'll print them.\n# You might also use io.BytesIO to collect them into a single bytes object for testing.\n\n# Example of consuming chunks (e.g., writing to a file)\n# with open('output.zip', 'wb') as f:\n#     for chunk in zipped_chunks:\n#         f.write(chunk)\n\nprint(\"Generated ZIP chunks (first few bytes of each):\")\nfor i, chunk in enumerate(zipped_chunks):\n    print(f\"Chunk {i}: {len(chunk)} bytes (starts with: {chunk[:20]})\")\n    if i > 5: # Limit output for demonstration\n        print(\"...\")\n        break","lang":"python","description":"This quickstart demonstrates how to use `stream_zip` to create a ZIP archive containing multiple files and a directory. The `stream_zip` function takes an iterable of member file definitions, where each member file is a tuple specifying its name, modification time, mode, compression method (`ZIP_32` or `ZIP_64`), and an iterable of binary content chunks. The function returns an iterable that yields chunks of the resulting ZIP file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.0.84","pypi_latest":"0.0.84","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.2,"avg_import_s":0.25,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.13,"mem_mb":5.4,"disk_size":"26.4M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.1,"mem_mb":5.4,"disk_size":"27M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.22,"mem_mb":6.7,"disk_size":"29.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.21,"mem_mb":6.7,"disk_size":"30M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.4,"mem_mb":8.3,"disk_size":"21.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.41,"mem_mb":8.3,"disk_size":"22M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.41,"mem_mb":8.8,"disk_size":"20.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.38,"mem_mb":8.8,"disk_size":"22M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.13,"mem_mb":5.3,"disk_size":"25.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"stream-zip","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.4,"import_time_s":0.12,"mem_mb":5.3,"disk_size":"27M"}]}}