google.appengine.ext.zipserve package


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.:

  • url: /images/.* script: $PYTHON_LIB/google/appengine/ext/zipserve

This would invoke a main() within zipserve/ This code would then take the URL path, and look for a .zip file under the first component of the path, in this case “” 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

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(‘’)),


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().


class google.appengine.ext.zipserve.ZipHandlersource

Bases: google.appengine.ext.webapp._webapp25.RequestHandler

Request handler serving static files from zipfiles.

MAX_AGE = 600
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.

  • zipfilename – The name of the zipfile.

  • name – The name within the zipfile.


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().

  • prefix – The zipfilename without the .zip suffix.

  • name – The name within the zipfile.

zipfile_cache = {}

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.

  • zipfilename – The filename of a zipfile.

  • max_age – Optional expiration time; defaults to ZipHandler.MAX_AGE.

  • public – Optional public flag; defaults to ZipHandler.PUBLIC.


A ZipHandler subclass.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

App Engine standard environment for Python