Skip to main content

html2epub

简介 / Introduction

原项目为 python2 项目 pypub,此为 python3 项目,并进行了些许修改与优化。

This project is a Python 3 fork of the original pypub (Python 2), with various improvements and optimizations.

将 HTML 链接、HTML 文件或 HTML 文本转换成 EPUB 文件。

Converts HTML links, HTML files, or HTML text into EPUB files.

tips / 提示

关于 EPUB 文件的格式可以参考 EPUB - Wikipedia

For EPUB format details, refer to EPUB - Wikipedia.

快速使用 / Quick Start

>>> import html2epub
>>> epub = html2epub.Epub('My First Epub')
>>> chapter = html2epub.create_chapter_from_url('https://en.wikipedia.org/wiki/EPUB')
>>> epub.add_chapter(chapter)
>>> epub.create_epub('OUTPUT_DIRECTORY')

安装 / Installation

pip install beautifulsoup4 jinja2 lxml requests
# 或使用 requirements.txt
# or install from requirements.txt
pip install -r requirements.txt

功能特性 / Features

  • 从 URL 创建章节 / Create chapters from URLs
  • 从 HTML 文件创建章节 / Create chapters from HTML files
  • 从 HTML 字符串创建章节 / Create chapters from HTML strings
  • 自动清理 HTML 内容 / Automatically clean HTML content
  • 支持 CSS 样式 / Support CSS styles
  • 支持图片嵌入 / Support image embedding
  • 完整的元数据支持 / Full metadata support

API 参考 / API Reference

Epub 类 / Epub Class

epub = html2epub.Epub('Book Title', author='Author Name')
epub.add_chapter(chapter)
epub.set_cover('cover.jpg')
epub.create_epub('output_directory')

创建章节 / Creating Chapters

# 从 URL 创建 / Create from URL
chapter = html2epub.create_chapter_from_url('https://example.com')

# 从文件创建 / Create from file
chapter = html2epub.create_chapter_from_file('path/to/file.html')

# 从字符串创建 / Create from string
chapter = html2epub.create_chapter_from_string('<h1>Hello</h1><p>World</p>')

测试 / Testing

python run_tests.py

Python 版本支持 / Python Version Support

  • Python 3.8+
  • 已测试并兼容 Python 3.12 和 3.13 / Tested and compatible with Python 3.12 and 3.13

参考文献 / References

  1. wcember/pypub: Python library to programatically create epub files.
  2. EPUB - Wikipedia.

许可证 / License

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

html2epub-1.3.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

html2epub-1.3-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file html2epub-1.3.tar.gz.

File metadata

  • Download URL: html2epub-1.3.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for html2epub-1.3.tar.gz
Algorithm Hash digest
SHA256 e0853aed3b2cc33e6cd5f2d762d1b45504bed7f1135160abea6b9e520424f14f
MD5 201cc1ff92b3c3eaffbd157bd7e9de66
BLAKE2b-256 960394995ebedd6e12e199ebb1ddb29bc919a7f2badd1747fc540ddfe62dbbbb

See more details on using hashes here.

File details

Details for the file html2epub-1.3-py3-none-any.whl.

File metadata

  • Download URL: html2epub-1.3-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for html2epub-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ce93f14633531e2a1388f9ba00a664a0546d3e76ca59a46ce7d3895985772720
MD5 00e84f723cc44b104c1636487c500c53
BLAKE2b-256 ff0dd26089f19cd3628b304f43b86ea7f5ea0affdfe15ad6799e12651bc1bd91

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3 This release

2 files

1.2

2 files

1.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page