This is the initial implementation of the Imposition library, a Python library intended to run under Pyodide for parsing and rendering EPUB files.
This package is not yet available on PyPI. To install it, you must build the wheel from the source and then install it using pip:
hatch build
pip install dist/imposition-0.1.0-py3-none-any.whlThe library and demo require Pyodide v0.29.1 or later.
The following example demonstrates how to load an EPUB file and render it in a web page.
import asyncio
import js
from imposition.book import Book
from imposition.rendition import Rendition
async def main():
response = await js.pyfetch("test_book.epub")
epub_bytes_proxy = await response.bytes()
epub_bytes = epub_bytes_proxy.to_py()
book = Book(epub_bytes)
rendition = Rendition(book, "viewer")
js.window.rendition = rendition
rendition.display_toc()
rendition.display(book.spine[0])
if __name__ == "__main__":
asyncio.run(main())Contributions are welcome! Please see the Contributing Guidelines for more information on how to get started.
For a detailed list of changes, please see the Changelog.
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
The library uses a custom exception hierarchy to report errors during EPUB parsing. All exceptions inherit from imposition.ImpositionError.
ImpositionError: The base class for all exceptions in the library.InvalidEpubError: Raised for general EPUB format errors, such as malformed XML files or missing required elements.MissingContainerError: A subclass ofInvalidEpubError, raised specifically when theMETA-INF/container.xmlfile is not found in the EPUB archive.
When using the library, it's recommended to wrap the Book constructor in a try...except block to handle these potential errors:
from imposition import Book, ImpositionError
try:
book = Book(epub_bytes)
except ImpositionError as e:
print(f"Error loading book: {e}")For a detailed competitive analysis and the strategic reasoning behind this roadmap, please see COMPETITIVE_ANALYSIS.md.
Note: The following roadmap is a strategic overview. For the most up-to-date list of priorities, please see the GitHub issue tracker.
- Table of Contents:
- Priority: High
- Rationale: Essential for basic navigation.
- Chapter Navigation (Next/Previous):
- Priority: High
- Rationale: Core functionality for a reading application.
- Font Size Adjustment:
- Priority: Medium
- Rationale: A common and expected feature for readability.
- Location & Pagination (CFI):
- Priority: High
- Rationale: Enables saving and restoring the user's position.
- Custom Themes (Light/Dark):
- Priority: Medium
- Rationale: A popular feature for user comfort.
- Search (within the book):
- Priority: Medium
- Rationale: A valuable tool for research and navigation.
- Annotations (Highlighting & Notes):
- Priority: High
- Rationale: A key feature for students, researchers, and active readers.
- Bookmarks:
- Priority: Medium
- Rationale: A user-friendly way to save important locations.
- Spreads (Two-page view):
- Priority: Low
- Rationale: A nice-to-have feature, but not essential for a first version.
- Accessibility Features (TTS, Dyslexia Fonts):
- Priority: High
- Rationale: A key differentiator and a socially responsible goal.
- OPDS Catalog Support:
- Priority: Medium
- Rationale: Enables users to browse and add books from online catalogs.
- DRM (LCP) Support:
- Priority: Low
- Rationale: A complex feature that is only necessary for commercial applications.
