Skip to main content

Ebook library which can handle EPUB2/EPUB3 and Kindle format

Project description

About EbookLib

EbookLib is a Python library for managing EPUB2/EPUB3 and Kindle files. It's capable of reading and writing EPUB files programmatically (Kindle support is under development).

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 <https://github.com/sourcefabric/Booktype/>_ from Sourcefabric, as well as sprits-it! <https://github.com/the-happy-hippo/sprits-it>, fanfiction2ebook <https://github.com/ltouroumov/fanfiction2ebook>, viserlalune <https://github.com/vjousse/viserlalune>_ and Telemeta <https://github.com/Parisson/Telemeta>_.

Packages of EbookLib for GNU/Linux are available in Debian <https://packages.debian.org/python-ebooklib>_ and Ubuntu <http://packages.ubuntu.com/python-ebooklib>_.

Sphinx documentation is generated from the templates in the docs/ directory and made available at http://ebooklib.readthedocs.io

Usage

Reading

import ebooklib
from ebooklib import epub

book = epub.read_epub('test.epub')

for image in book.get_items_of_type(ebooklib.ITEM_IMAGE):
    print(image)

Writing

from ebooklib import epub

book = epub.EpubBook()

# set metadata
book.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 chapter
c1 = 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 image
image_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 chapter
book.add_item(c1)
# add image
book.add_item(img)

# define Table Of Contents
book.toc = (
    epub.Link("chap_01.xhtml", "Introduction", "intro"),
    (epub.Section("Simple book"), (c1,)),
)

# add default NCX and Nav file
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())

# define CSS style
style = "BODY {color: white;}"
nav_css = epub.EpubItem(
    uid="style_nav",
    file_name="style/nav.css",
    media_type="text/css",
    content=style,
)

# add CSS file
book.add_item(nav_css)

# basic spine
book.spine = ["nav", c1]

# write to the file
epub.write_epub("test.epub", book, {})

License

EbookLib is licensed under the AGPL license <LICENSE.txt>_.

Authors

Full list of authors is in AUTHORS.txt <AUTHORS.txt>_ file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EbookLib-MD-0.20.tar.gz (115.5 kB view details)

Uploaded Source

Built Distribution

EbookLib_MD-0.20-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file EbookLib-MD-0.20.tar.gz.

File metadata

  • Download URL: EbookLib-MD-0.20.tar.gz
  • Upload date:
  • Size: 115.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for EbookLib-MD-0.20.tar.gz
Algorithm Hash digest
SHA256 a84f7f1a704837b91bf57d1d7e60b095cad0a51fe62c5579f74d3c8b24d996e5
MD5 951bbcbd2212d5c1693532b4e939dd0e
BLAKE2b-256 3e9b8d27989ff0119df628e69d4c8e39a27988e25beef1e461e0612b40c56a81

See more details on using hashes here.

File details

Details for the file EbookLib_MD-0.20-py3-none-any.whl.

File metadata

  • Download URL: EbookLib_MD-0.20-py3-none-any.whl
  • Upload date:
  • Size: 38.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for EbookLib_MD-0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 e6bdafb306ed89c5c65633b5b393e045aef2e513995dafa335bf96ae02fe2215
MD5 3895717c1bc56addee23ec6305170947
BLAKE2b-256 12f9562dd91690cc7dcffe8649e3aaa0695816494c32e36aaa36c570152f0f51

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page