Django extension to assemble ZIP archives dynamically using Nginx with mod_zip.
ZIP archive generation alternatives such as ZipStream can tie up web server threads and make Python do the heavy lifting. To achieve higher performance, django-zip-stream offloads ZIP archive generation to Nginx/mod_zip which frees up web servers to serve other clients.
To use this library, setup Nginx (with mod_zip installed) as a reverse proxy for your Python web app.
- Django 1.7 +
- Python 3.4 +
- Nginx 0.7.25 or later compiled with mod_zip (i.e. from https://hub.docker.com/r/yspreen/nginx)
See the Travis CI build matrix for detailed information regarding the latest master.
pip install git+https://github.com/y-spreen/django-zip-stream.git
from django_zip_stream.responses import TransferZipResponse
def download_zip(request):
# Files are located at /home/travis but Nginx is configured to serve from /data
files = [
("/chicago.jpg", "/data/home/travis/chicago.jpg", 4096),
("/portland.jpg", "/data/home/travis/portland.jpg", 4096),
]
return TransferZipResponse(filename='download.zip', files=files)
# Compile Nginx with mod_zip - https://github.com/evanmiller/mod_zip server { listen 80; # Replace the following with the IP/port of your Python web application location / { proxy_pass http://192.168.12.41:8000; } # Configure nginx to serve files with absolute paths from an internal location # mod_zip location helper # Note: The leading ^~ is essential here, no more checks should be done after this match location ^~ /data/ { root /; internal; } }
- Documentation: https://django-zip-stream.readthedocs.io
- PyPI page: http://pypi.python.org/pypi/django-zip-stream
- Code repository: https://github.com/travcunn/django-zip-stream
- Bugtracker: https://github.com/travcunn/django-zip-stream/issues
- Continuous integration: https://travis-ci.org/travcunn/django-zip-stream
- Roadmap: https://github.com/travcunn/django-zip-stream/milestones