Skip to main content

A simplest EPUB file generator with image support.

Project description

EPUB Generator

EPUB Generator is a simplest Python library for creating EPUB e-books with support for images and HTML content.


Table of Contents


Installation

Install the library with pip:

pip install simplest_epub_generator

Examples

Example 1: Creating a book with plain text and images

from pathlib import Path
from simplest_epub_generator import Chapter, Epub


chapter1 = Chapter(
    title="Chapter 1",
    text="This is the text of the first chapter. \nNew paragraph."
)

chapter2 = Chapter(
    title="Chapter 2",
    text="This is the text of the second chapter. <img src='./images/example.jpg' />"
)

book = Epub(book_name="Simple Book", author="Author")
book.add_chapters([chapter1, chapter2])
book.write_file(Path("./simple_book.epub"))

Example 2: Creating a book with HTML content and images

from pathlib import Path
from simplest_epub_generator import Chapter, Epub


chapter1 = Chapter(
    title="<h1>HTML Chapter</h1>",
    text="<p>Text with <strong>HTML</strong>.</p><img src='./images/example.jpg' />",
    is_html=True
)

book = Epub(book_name="HTML Book", author="Author")
book.add_chapter(chapter1)
book.write_file(Path("./html_book.epub"))

API

Chapter Class

A class representing a chapter in an EPUB book.

Constructor parameters

  • title (str): Title of the chapter.
  • text (str): Text content of the chapter.
  • is_html (bool, optional): Flag indicating if title and text contain HTML markup. Defaults to False.
  • lang (str, optional): Language of the chapter. Defaults to "eng".

Class attributes

  • self.title (str): Title of the chapter.
  • self.html_content (str): A variable containing the title and text in HTML format.
  • self.lang (str): Language of the chapter.

Methods

  • remove_tags(html: str) -> str: Removes HTML tags from a string.
  • get_image_paths() -> Set[str]: Extracts image paths from the chapter's HTML content.

Epub Class

A class for creating and managing an EPUB book.

Constructor parameters

  • book_name (str): Name of the book.
  • lang (str, optional): Language of the book. Defaults to "eng".
  • author (str, optional): Author of the book. Defaults to an empty string.

Class attributes

  • self.book_name (str): Name of the book.
  • self.lang (str): Language of the book.
  • self.author (str): Author of the book.

Methods

  • add_chapter(chapter: Chapter): Adds a chapter to the book.
  • add_chapters(chapters: List[Chapter]): Adds multiple chapters to the book.
  • write_file(path: Path): Saves the book to a file at the specified path.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplest_epub_generator-0.1.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file simplest_epub_generator-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for simplest_epub_generator-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 515777b837f1b84db843a8cb1c6eee436f87ecb7fece9144c80738428e9bc267
MD5 a4c7e6ead68f2725260b7a91bca3c42d
BLAKE2b-256 12a1550d5b802cfcc9c72295e9b18a7d9776eee0cd18ac8cfe20babbe617cbfc

See more details on using hashes here.

Supported by

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