EbookLib is a Python library for managing EPUB2/EPUB3 and Kindle files. It's capable of reading and writing EPUB files programmatically.
We are working on refreshing the project so please check and comment if you have your own ideas what needs to happen with the project.
The API is designed to be as simple as possible, while at the same time making complex things possible too. It has support for covers, table of contents, spine, guide, metadata and etc.
EbookLib is used in Booktype from Sourcefabric, as well as sprits-it!, fanfiction2ebook, viserlalune and Telemeta.
Packages of EbookLib for GNU/Linux are available in Debian and Ubuntu.
Sphinx documentation is generated from the templates in the docs/ directory and made available at http://ebooklib.readthedocs.io
importebooklibfromebooklibimportepubbook=epub.read_epub('test.epub')
forimageinbook.get_items_of_type(ebooklib.ITEM_IMAGE):
print(image)fromebooklibimportepubbook=epub.EpubBook()
# set metadatabook.set_identifier("id123456")
book.set_title("Sample book")
book.set_language("en")
book.add_author("Author Authorowski")
book.add_author(
"Danko Bananko",
file_as="Gospodin Danko Bananko",
role="ill",
uid="coauthor",
)
# create chapterc1=epub.EpubHtml(title="Intro", file_name="chap_01.xhtml", lang="hr")
c1.content= (
"<h1>Intro heading</h1>""<p>Zaba je skocila u baru.</p>"'<p><img alt="[ebook logo]" src="static/ebooklib.gif"/><br/></p>'
)
# create image from the local imageimage_content=open("ebooklib.gif", "rb").read()
img=epub.EpubImage(
uid="image_1",
file_name="static/ebooklib.gif",
media_type="image/gif",
content=image_content,
)
# add chapterbook.add_item(c1)
# add imagebook.add_item(img)
# define Table Of Contentsbook.toc= (
epub.Link("chap_01.xhtml", "Introduction", "intro"),
(epub.Section("Simple book"), (c1,)),
)
# add default NCX and Nav filebook.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())
# define CSS stylestyle="BODY {color: white;}"nav_css=epub.EpubItem(
uid="style_nav",
file_name="style/nav.css",
media_type="text/css",
content=style,
)
# add CSS filebook.add_item(nav_css)
# basic spinebook.spine= ["nav", c1]
# write to the fileepub.write_epub("test.epub", book, {})EbookLib is licensed under the AGPL license.
Full list of authors is in AUTHORS.txt file.