Skip to main content

Clean-room Python EPUB conformance checker driven by EPUBCheck behavior specs

Project description

PyPI - Version PyPI - Python Version PyPI - Downloads

pyepubcheck

pyepubcheck is a clean-room Python EPUB validation project driven by the imported EPUBCheck behavior specifications in specs/behavior/features.

The package intentionally uses a flat layout: importable code lives in ./pyepubcheck, not in ./src.

Status: 0.1.0 alpha. The project is suitable for validating the behavior covered by its current test suite and SpecMason mappings. It is not yet a complete drop-in replacement for the Java EPUBCheck distribution.

Features

  • CLI command named pyepubcheck.
  • Validation of expanded EPUB directories and individual OPF, XHTML, SVG, navigation, CSS, NCX, and media overlay resources.
  • EPUB 2 and EPUB 3 behavior coverage derived from Gherkin scenarios.
  • Optional profile checks for dictionaries, EDUPUB, indexes, previews, accessibility, and related profile constraints.
  • Console, JSON, XML, and XMP report renderers.
  • Read-only publication inspection for metadata, manifest items, images, navigation, and text statistics.
  • Image inventory reports with media type, byte size, dimensions, manifest properties, and references.
  • Metadata reports for OPF Dublin Core fields, rendition metadata, accessibility-related entries, and package identifiers.
  • Custom message override support compatible with the project acceptance tests.
  • SpecMason configuration for tracking Gherkin-to-test coverage.

Requirements

  • Python 3.10 or newer.
  • Runtime dependencies declared in pyproject.toml:
    • click
    • defusedxml
    • jsonpath-ng
    • lxml
    • tinycss2

Installation

From PyPI after publication:

python -m pip install pyepubcheck

From a local checkout:

git clone <repository-url>
cd pyepubcheck
python -m pip install -e .

For development, tests, and documentation:

python -m pip install -e ".[dev,docs]"

Quick start

Validate an expanded EPUB directory:

pyepubcheck path/to/book/

Validate packaged EPUB archive structure or a single resource:

pyepubcheck book.epub
pyepubcheck OPS/package.opf
pyepubcheck OPS/chapter-001.xhtml

Inspect a publication:

pyepubcheck inspect book.epub
pyepubcheck images book.epub --sort size --largest 10
pyepubcheck metadata book.epub --format json
pyepubcheck stats book.epub --estimate-pages

Write a JSON report:

pyepubcheck book.epub --json report.json

Fail the command when warnings are present:

pyepubcheck book.epub --failonwarnings

Use a validation profile:

pyepubcheck book.epub --profile accessibility
pyepubcheck book.epub --profile edupub

CLI reference

usage: pyepubcheck [-h] [--version]
                   {check,inspect,images,metadata,manifest,nav,stats} ...

Legacy validation remains supported:

pyepubcheck book.epub

This behaves like:

pyepubcheck check book.epub

Primary commands:

Command Purpose
check Validate a publication and optionally append a compact clean-run summary.
inspect Produce an all-in-one read-only publication overview.
images List image assets, dimensions, byte sizes, properties, and references.
metadata Report stored OPF metadata and package identifiers.
manifest Report manifest items, resolved paths, and file presence.
nav Report TOC, landmarks, and page-list data.
stats Report estimated word and character counts and optional estimated pages.

Python API

from pyepubcheck.api import validate_path
from pyepubcheck.config import ValidationConfig
from pyepubcheck.severity import Severity

report = validate_path(
    "book.epub",
    config=ValidationConfig(profile="accessibility", fail_on_warnings=True),
)

for message in report.messages:
    print(message.severity.value, message.id, message.message)

exit_code = report.exit_code(fail_on_warnings=True)
assert exit_code in {0, 1}
assert all(message.severity is not Severity.FATAL for message in report.messages)

Documentation

The documentation is authored as Markdown under docs/ and rendered with MyST Parser.

Build it locally:

python -m pip install -e ".[docs]"
sphinx-build -b html docs docs/_build/html

Start with docs/index.md.

Development

python -m pip install -e ".[dev,docs]"
python -m pytest -q
ruff check .
specmason check --json
specmason coverage --json --show gaps

The SpecMason configuration lives in specmason.toml; the imported Gherkin corpus lives under specs/behavior/features.

Release checklist

  1. Update pyepubcheck/__init__.py and pyproject.toml to the release version.
  2. Run the test suite: python -m pytest -q.
  3. Run SpecMason checks: specmason check --json.
  4. Build the docs: sphinx-build -b html docs docs/_build/html.
  5. Build distributions: python -m build.
  6. Inspect distributions: python -m twine check dist/*.
  7. Publish to TestPyPI, install into a clean virtual environment, then publish to PyPI.

License

MIT. See LICENSE.

Attribution

This project is a clean-room Python implementation guided by public EPUB behavior specifications and test scenarios. It is not affiliated with, endorsed by, or maintained by the EPUBCheck project.

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

pyepubcheck-0.1.0.tar.gz (74.5 kB view details)

Uploaded Source

Built Distribution

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

pyepubcheck-0.1.0-py3-none-any.whl (96.2 kB view details)

Uploaded Python 3

File details

Details for the file pyepubcheck-0.1.0.tar.gz.

File metadata

  • Download URL: pyepubcheck-0.1.0.tar.gz
  • Upload date:
  • Size: 74.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyepubcheck-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf6ef01848bea7af6c0f5f26a53498becc3bf448e6bc42a5899b1c0c9728253b
MD5 c37552952629b1ef928424d51073f96e
BLAKE2b-256 29c300527040ef898dd88bd3d7630c7b28f3945eb87c3637aaec536530a5692b

See more details on using hashes here.

File details

Details for the file pyepubcheck-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyepubcheck-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 96.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyepubcheck-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9dcc3fe66047a2fb427605866b11e6e179855e10c4d56da8e7408be79185e54
MD5 15938fa6428509f523b5673ffdd65a56
BLAKE2b-256 4066dcf0a7fe45e95b172ac883bf7b634d5c18345d35167689daf837eb4c7e5e

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