def initialize_container(path_to_container, opf_name='metadata.opf', extra_entries=[]):
 rootfiles = ''
 for (path, mimetype, _) in extra_entries:
  rootfiles += u'<rootfile full-path="{0}" media-type="{1}"/>'.format(path, mimetype)
 CONTAINER = u'<?xml version="1.0"?>\n<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">\n   <rootfiles>\n      <rootfile full-path="{0}" media-type="application/oebps-package+xml"/>\n      {extra_entries}\n   </rootfiles>\n</container>\n    '.format(opf_name, extra_entries=rootfiles).encode('utf-8')
 zf = ZipFile(path_to_container, 'w')
 zf.writestr('mimetype', 'application/epub+zip', compression=ZIP_STORED)
 zf.writestr('META-INF/', '', 493)
 zf.writestr('META-INF/container.xml', CONTAINER)
 for (path, _, data) in extra_entries:
  zf.writestr(path, data)
 return zf

def initialize_container ( path_to_container , opf_name = 'metadata.opf' , extra_entries = [ ] ) : rootfiles = '' for ( path , mimetype , _ ) in extra_entries : rootfiles += u'<rootfile full-path="{0}" media-type="{1}"/>' . format ( path , mimetype ) CONTAINER = u'<?xml version="1.0"?>\n<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">\n   <rootfiles>\n      <rootfile full-path="{0}" media-type="application/oebps-package+xml"/>\n      {extra_entries}\n   </rootfiles>\n</container>\n    ' . format ( opf_name , extra_entries = rootfiles ) . encode ( 'utf-8' ) zf = ZipFile ( path_to_container , 'w' ) zf . writestr ( 'mimetype' , 'application/epub+zip' , compression = ZIP_STORED ) zf . writestr ( 'META-INF/' , '' , 493 ) zf . writestr ( 'META-INF/container.xml' , CONTAINER ) for ( path , _ , data ) in extra_entries : zf . writestr ( path , data ) return zf
create an empty epub document .