Metadata-Version: 2.4
Name: epubkit
Version: 0.1.0.post202512301248
Summary: A comprehensive EPUB processing toolkit for Python
License: MIT License
        
        Copyright (c) 2024 epubkit
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup :: XML
Requires-Python: >=3.8
Requires-Dist: beautifulsoup4>=4.9.0
Requires-Dist: lxml>=4.9.0
Provides-Extra: cache
Requires-Dist: cachetools>=5.0.0; extra == 'cache'
Description-Content-Type: text/markdown

# 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

```bash
pip install epubkit
```

## Quick Start

```python
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:

```python
# 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:

```python
# 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):

```python
# 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:

```python
# 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
