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 iftitleandtextcontain HTML markup. Defaults toFalse.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simplest_epub_generator-0.1.3-py3-none-any.whl.
File metadata
- Download URL: simplest_epub_generator-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d43feb8067fc7431d7bfafed9d5c0887d997d7104fea2941f39e5bb3e3e9f22
|
|
| MD5 |
b8eca7a1eddbf80fdf4b653183e46714
|
|
| BLAKE2b-256 |
c43a080031b492eba0e4a4e761b6d59100edee4db013b7c32e0b329de27740ae
|