Skip to main content

about ebooklib.changyy

Please use ebooklib first - https://github.com/aerkalov/ebooklib:

$ pip install ebooklib

Here is https://github.com/changyy/ebooklib, used for preliminary testing of ebooklib. All experiments will contribute back to https://github.com/aerkalov/ebooklib.

Current tasks for the project include:


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.

Metadata

Release files for EbookLib.changyy 0.18.2023.1221.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for EbookLib.changyy 0.18.2023.1221.0
File Size Uploaded
EbookLib.changyy-0.18.2023.1221.0.tar.gz 117.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for EbookLib.changyy 0.18.2023.1221.0
File Interpreter ABI Platform
EbookLib.changyy-0.18.2023.1221.0-py3-none-any.whl Python 3 none any Details

Total release size: 157.4 kB

Release files / EbookLib.changyy-0.18.2023.1221.0.tar.gz

Download URL EbookLib.changyy-0.18.2023.1221.0.tar.gz
Size 117.0 kB
Tags Source
SHA-256 checksum
How to use checksums
eb486f38b860fa000eb6b76c03e48cc9e4ccc0f1ac4cf411fd5b8561560499ad
BLAKE2b-256 checksum
How to use checksums
bffd60657f5efc40a3b3fc5a9110015e45e42be4d16279825ba3ba515cddbc7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / EbookLib.changyy-0.18.2023.1221.0-py3-none-any.whl

Download URL EbookLib.changyy-0.18.2023.1221.0-py3-none-any.whl
Size 40.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7b44fc4a5a402e9cdc706f102d9865cdd1d62e3c501d0c0a854172ef556c7e9
BLAKE2b-256 checksum
How to use checksums
962d917355fe15647c245c5823ce50fa102326a389c9ffbd225397edd861bed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.18.2023.1221.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page