Skip to main content

Simple minimalistic library for creating EPUB3 files

Project description

Build Status Coverage Status license

mkepub

mkepub is a minimalistic library for creating .epub files.

Pros:

  • Easy to use, minimalistic API.

  • Automatically generated TOC.

  • Support for nested TOC of any depth.

  • Support for embedded images.

  • In-progress books are stored on disk rather than in memory, enabling creation of large (5000+ pages, 20+ MiBs) epub files.

  • Adherence to the EPUB3 specs.

  • Support for most of the EPUB metadata, including language, subject, description, and rights.

Cons:

  • No support for custom page filenames or directory structure.

  • No support for reading or editing epub files.

  • No support for font-embedding or most other less commonly used EPUB features.

  • No content validation - using broken or unsupported html code as page content will lead to mkepub successfully creating a .epub file that does not meet EPUB3 specifications.

  • Probably other issues.

Basic Usage

import mkepub

book = mkepub.Book(title='An Example')
book.add_page(title='First Page', content='Lorem Ipsum etcetera.')
book.save('example.epub')

Advanced Usage

import mkepub

book = mkepub.Book(title='Advanced Example', author='The Author')
# multiple authors can be specified as a list:
# mkepub.Book(title='Advanced Example', authors=['The First Author', 'The Second Author'])
with open('cover.jpg', 'rb') as file:
    book.set_cover(file.read())
with open('style.css') as file:
    book.set_stylesheet(file.read())

first = book.add_page('Chapter 1', 'And so the book begins.')

child = book.add_page('Chapter 1.1', 'Nested TOC is supported.', parent=first)
book.add_page('Chapter 1.1.1', 'Infinite nesting levels', parent=child)
book.add_page('Chapter 1.2', 'In any order you wish.', parent=first)

book.add_page('Chapter 2', 'Use <b>html</b> to make your text <span class="pink">prettier</span>')

book.add_page('Chapter 3: Images', '<img src="images/chapter3.png" alt="You can use images as well">')
# as long as you add them to the book:
with open('chapter3.png', 'rb') as file:
    book.add_image('chapter3.png', file.read())

book.save('advanced.epub')

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

mkepub-1.2.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file mkepub-1.2.tar.gz.

File metadata

  • Download URL: mkepub-1.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3

File hashes

Hashes for mkepub-1.2.tar.gz
Algorithm Hash digest
SHA256 6ef8336327c0e15348ed721d9ae16d6746228a7bc4a47360aaad553c2b74602c
MD5 2d39b405797d5bcc7287482f4c3e750d
BLAKE2b-256 fc2e138d404f7cb057a3390b9a75dc757e737b40735d48663f9a7160b8a2dcc9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page