Skip to main content

A comprehensive EPUB processing toolkit for Python

Project description

epubkit

A comprehensive EPUB processing toolkit for Python.

Features

  • EPUB Reading: Parse EPUB files with support for EPUB2/3 standards
  • Table of Contents: Extract and navigate book structure
  • Content Access: Read chapters and access metadata
  • CFI Support: Canonical Fragment Identifier parsing and generation
  • Layout Properties: Access EPUB3 layout and rendering properties
  • Enhanced Spine: Rich spine item information with properties
  • Hook System: Extensible event system for customization
  • Extensible: Plugin architecture for different content sources

Installation

pip install epubkit

Quick Start

import epubkit

# Open an EPUB file
book = epubkit.open("my_book.epub")

# Access metadata
print(f"Title: {book.title}")

# Navigate chapters
for chapter in book.spine:
    print(f"- {chapter['title']}")

# Read content
content = book.read_chapter("chapter1.xhtml")

# CFI support
cfi = epubkit.CFIGenerator.generate_cfi(spine_index, node, offset)

Enhanced Features

Layout Properties

Access EPUB3 layout and rendering properties from the OPF file:

# Get layout properties
layout = book.layout_properties
print(f"Layout: {layout.get('layout')}")           # pre-paginated/reflowable
print(f"Flow: {layout.get('flow')}")               # paginated/scrolled
print(f"Reading direction: {layout.get('page_progression_direction')}")  # ltr/rtl

Enhanced Spine Items

Access rich spine item information with properties:

# Get enhanced spine items
for item in book.spine_items:
    print(f"Chapter: {item.href}")
    print(f"Linear: {item.linear}")                # True/False
    print(f"Properties: {item.properties}")        # ['rendition:layout-pre-paginated']

Spine CFI Generation

Generate CFIs for spine items (useful for bookmarks):

# Generate CFI for first chapter
cfi = book.get_spine_cfi(0)
print(f"Chapter CFI: {cfi}")  # epubcfi(/6/2[chapter1]/)

Hook System

Use the extensible hook system for customization:

# Register event handlers
def on_toc_built(epub_instance, toc_data):
    print(f"TOC built with {len(toc_data['raw_chapters'])} chapters")

def on_chapter_loaded(epub_instance, href, content):
    print(f"Loaded chapter: {href}")

book.hooks.toc_built.register(on_toc_built)
book.hooks.chapter_loaded.register(on_chapter_loaded)

# Hooks are triggered automatically during normal operations
_ = book.toc  # Triggers toc_built hook
content = book.read_chapter("chapter1.xhtml")  # Triggers chapter_loaded hook

Available hooks:

  • toc_built: After TOC is built
  • toc_parsed: After TOC structure is parsed
  • metadata_extracted: After metadata is extracted
  • layout_parsed: After layout properties are parsed
  • spine_processed: After spine items are processed
  • content_parsed: After chapter content is parsed
  • chapter_loaded: After chapter is loaded from disk

License

MIT License

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

epubkit-0.1.0.post202512301248.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

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

epubkit-0.1.0.post202512301248-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file epubkit-0.1.0.post202512301248.tar.gz.

File metadata

  • Download URL: epubkit-0.1.0.post202512301248.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for epubkit-0.1.0.post202512301248.tar.gz
Algorithm Hash digest
SHA256 a48b33809b5e7f89718adbfd966a7fcbbfcbfd4714499581a64d323b5dd28442
MD5 b4ae1755f20308f565567860a3febb5f
BLAKE2b-256 f91ea0069a06642ca4e0a6ea66ccedd982524fadb9df6689bcf86fad218011c2

See more details on using hashes here.

File details

Details for the file epubkit-0.1.0.post202512301248-py3-none-any.whl.

File metadata

File hashes

Hashes for epubkit-0.1.0.post202512301248-py3-none-any.whl
Algorithm Hash digest
SHA256 42f734db67c8af5d97c6ef09797fb3f68dedb185297b5b14e5ba61c104ba234e
MD5 56f4389feb371bba25545f2a7f0a9ded
BLAKE2b-256 29d8dfc6633aeef33a8d0f078490aec51cbc9f2c2c9d677603d478c41349a418

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