UCFlib

A library for reading and writing UCF and EPUB formats
Download

UCFlib Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • David Buxton
  • Publisher web site:
  • http://github.com/davidwtbuxton/

UCFlib Tags


UCFlib Description

UCFlib is a Python module for reading and writing UCF and EPUB formats. It has been tested with Python 2.7 and 3.2.The UCF format is used by Adobe for some of its products, including InDesign IDML. The EPUB format for digital books is effectively UCF, so UCFlib can be used to read and write EPUB files.UCFlib is provided under the MIT license.Reading a fileimport ucf# Open an existing fileebook = ucf.UCF(filename='example.epub')An instance of UCF is an ordered dictionary. Keys are the names of files in the archive. Keys are always unicode strings. The values are the contents of the files. The values are always byte strings.list(ebook.keys())You can create a new empty UCF instance and set its mimetype in one go:idml = ucf.UCF(mimetype='application/vnd.adobe.indesign-idml-package')idml.mimetype # Now set to the InDesign mime typeThe mimetype property is a convenience for accessing the 'mimetype' file in the archive. The UCF specification states that the value must an ASCII string, so if you assign a unicode string UFClib will encode it for you:ebook.mimetype# Equivalent toebookebook.mimetype = 'application/epub+zip'The EPUB specification requires a 'META-INF/container.xml' file in the archive. You can use a shortcut to refer to any file in the 'META-INF' directory in the archive:ebook.meta# Equivalent toebookThe special 'META-INF/container.xml' file is used to find the main document in the archive. You can access the names and mime-types using the 'rootfiles' property, a list of tuples:ebook.rootfilesTo save the archive to a different file:ebook.save(filename='updated-example.epub')The filename argument can be either a path string or a file-like object open for writing. If you don't pass a filename the archive will be saved to the file given when opening it (if any).Product's homepage


UCFlib Related Software