Python 2.7 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Python.
Stay organized with collections
Save and categorize content based on your preferences.
google.appengine.ext.zipserve package
Summary
Serve static files from a zipfile.
This is a solution for apps that want to serve 1000s of small static
files while staying withing the 1000 file limit.
The simplest use case is driven purely from the handlers section in
app.yaml, e.g.:
This would invoke a main() within zipserve/__init__.py. This code
would then take the URL path, and look for a .zip file under the first
component of the path, in this case “images.zip” in the app’s working
directory. If found, it will then serve any matching paths below that
from the zip file. In other words, /images/foo/icon.gif would map to
foo/icon.gif in the zip file images.zip.
You can also customize the behavior by adding a custom line to your
WSGIApplication() invocation:
- def main():
-
- app = webapp.WSGIApplication(
-
- [(‘/’, MainPage),
-
(‘/static/(.*)’, zipserve.make_zip_handler(‘staticfiles.zip’)),
])
You can pass max_age=N to the make_zip_handler() call to override the
expiration time in seconds, which defaults to 600.
To customize the behavior even more, you can subclass ZipHandler and
override the get() method, or override it and call ServeFromZipFile()
directly.
Note that by default, a Cache-control is added that makes these pages
cacheable even if they require authentication. If this is not what
you want, override ZipHandler.SetCachingHeaders().
Contents
- class google.appengine.ext.zipserve.ZipHandlersource
-
Bases: google.appengine.ext.webapp._webapp25.RequestHandler
Request handler serving static files from zipfiles.
- ServeFromZipFile(zipfilename, name)source
Helper for the GET request handler.
This serves the contents of file ‘name’ from zipfile
‘zipfilename’, logging a message and returning a 404 response if
either the zipfile cannot be opened or the named file cannot be
read from it.
Parameters
- SetCachingHeaders()source
-
Helper to set the caching headers.
Override this to customize the headers beyond setting MAX_AGE.
- get(prefix, name)source
GET request handler.
Typically the arguments are passed from the matching groups in the
URL pattern passed to WSGIApplication().
Parameters
- google.appengine.ext.zipserve.main()source
-
Main program.
This is invoked when this package is referenced from app.yaml.
- google.appengine.ext.zipserve.make_zip_handler(zipfilename, max_age=None, public=None)source
Factory function to construct a custom ZipHandler instance.
Parameters
-
zipfilename – The filename of a zipfile.
-
max_age – Optional expiration time; defaults to ZipHandler.MAX_AGE.
-
public – Optional public flag; defaults to ZipHandler.PUBLIC.
ReturnsA ZipHandler subclass.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003eThe \u003ccode\u003egoogle.appengine.ext.zipserve\u003c/code\u003e package allows serving static files from a zip file, enabling apps to serve thousands of small files while adhering to file limits.\u003c/p\u003e\n"],["\u003cp\u003eYou can configure basic usage of zipserve directly through the \u003ccode\u003eapp.yaml\u003c/code\u003e file, where specifying the URL and script will invoke the package to look for a matching zip file.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003emake_zip_handler()\u003c/code\u003e function allows for customized behavior by creating a specific \u003ccode\u003eZipHandler\u003c/code\u003e instance, including setting a custom expiration time (\u003ccode\u003emax_age\u003c/code\u003e) for the cached content.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eZipHandler\u003c/code\u003e class provides methods such as \u003ccode\u003eServeFromZipFile()\u003c/code\u003e, \u003ccode\u003eSetCachingHeaders()\u003c/code\u003e, and \u003ccode\u003eget()\u003c/code\u003e that can be overridden to further customize how files are served and cached from within the zip file.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ezipserve.main()\u003c/code\u003e is invoked when the package is called from \u003ccode\u003eapp.yaml\u003c/code\u003e to serve static content and to access content from within a zip file, based on the provided file paths.\u003c/p\u003e\n"]]],[],null,["# google.appengine.ext.zipserve package\n=====================================\n\nSummary\n-------\n\nServe static files from a zipfile.\n\nThis is a solution for apps that want to serve 1000s of small static\nfiles while staying withing the 1000 file limit.\n\nThe simplest use case is driven purely from the handlers section in\napp.yaml, e.g.:\n\n- url: /images/.\\*\n script: $PYTHON_LIB/google/appengine/ext/zipserve\n\nThis would invoke a main() within zipserve/__init__.py. This code\nwould then take the URL path, and look for a .zip file under the first\ncomponent of the path, in this case \"images.zip\" in the app's working\ndirectory. If found, it will then serve any matching paths below that\nfrom the zip file. In other words, /images/foo/icon.gif would map to\nfoo/icon.gif in the zip file images.zip.\n\nYou can also customize the behavior by adding a custom line to your\nWSGIApplication() invocation:\n\ndef main():\n:\n\n app = webapp.WSGIApplication(\n :\n\n \\[('/', MainPage),\n\n : ('/static/(.\\*)', zipserve.make_zip_handler('staticfiles.zip')),\n\n\n \\])\n\n\nYou can pass max_age=N to the make_zip_handler() call to override the\nexpiration time in seconds, which defaults to 600.\n\nTo customize the behavior even more, you can subclass ZipHandler and\noverride the get() method, or override it and call ServeFromZipFile()\ndirectly.\n\nNote that by default, a Cache-control is added that makes these pages\ncacheable even if they require authentication. If this is not what\nyou want, override ZipHandler.SetCachingHeaders().\n\nContents\n--------\n\n*class* google.appengine.ext.zipserve.ZipHandler[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/ext/zipserve#ZipHandler)\n\n: Bases: google.appengine.ext.webapp._webapp25.RequestHandler\n\n Request handler serving static files from zipfiles. \n\n MAX_AGE*= 600*\n : \n\n PUBLIC*= True*\n : \n\n ServeFromZipFile(zipfilename, name)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/ext/zipserve#ZipHandler.ServeFromZipFile)\n\n : Helper for the GET request handler.\n\n This serves the contents of file 'name' from zipfile\n 'zipfilename', logging a message and returning a 404 response if\n either the zipfile cannot be opened or the named file cannot be\n read from it.\n Parameters\n\n - zipfilename -- The name of the zipfile.\n\n - name -- The name within the zipfile.\n\n SetCachingHeaders()[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/ext/zipserve#ZipHandler.SetCachingHeaders)\n\n : Helper to set the caching headers.\n\n Override this to customize the headers beyond setting MAX_AGE. \n\n get(prefix, name)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/ext/zipserve#ZipHandler.get)\n\n : GET request handler.\n\n Typically the arguments are passed from the matching groups in the\n URL pattern passed to WSGIApplication().\n Parameters\n\n - prefix -- The zipfilename without the .zip suffix.\n\n - name -- The name within the zipfile.\n\n zipfile_cache*= {}*\n: \n\ngoogle.appengine.ext.zipserve.main()[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/ext/zipserve#main)\n\n: Main program.\n\nThis is invoked when this package is referenced from app.yaml. \n\ngoogle.appengine.ext.zipserve.make_zip_handler(zipfilename, max_age=None, public=None)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/ext/zipserve#make_zip_handler)\n\n: Factory function to construct a custom ZipHandler instance.\n\n Parameters\n\n - zipfilename -- The filename of a zipfile.\n\n - max_age -- Optional expiration time; defaults to ZipHandler.MAX_AGE.\n\n - public -- Optional public flag; defaults to ZipHandler.PUBLIC.\n\n Returns\n\n A ZipHandler subclass."]]