# About EbookLib
EbookLib is a Python library for managing EPUB2/EPUB3 and Kindle files. It's capable of reading and writing EPUB files programmatically (Kindle support is under development).
The API is designed to be as simple as possible, while at the same time making complex things possible too. It has support for covers, table of contents, spine, guide, metadata and etc.
EbookLib is used in `Booktype <https://github.com/sourcefabric/Booktype/>`_ from Sourcefabric, as well as `sprits-it! <https://github.com/the-happy-hippo/sprits-it>`_, `fanfiction2ebook <https://github.com/ltouroumov/fanfiction2ebook>`_, `viserlalune <https://github.com/vjousse/viserlalune>`_ and `Telemeta <https://github.com/Parisson/Telemeta>`_.
Packages of EbookLib for GNU/Linux are available in `Debian <https://packages.debian.org/python-ebooklib>`_ and `Ubuntu <http://packages.ubuntu.com/python-ebooklib>`_.
Sphinx documentation is generated from the templates in the docs/ directory and made available at http://ebooklib.readthedocs.io
# Usage
## Reading
```py
import ebooklib
from ebooklib import epub
book = epub.read_epub('test.epub')
for image in book.get_items_of_type(ebooklib.ITEM_IMAGE):
print(image)
```
## Writing
```py
from ebooklib import epub
book = epub.EpubBook()
# set metadata
book.set_identifier("id123456")
book.set_title("Sample book")
book.set_language("en")
book.add_author("Author Authorowski")
book.add_author(
"Danko Bananko",
file_as="Gospodin Danko Bananko",
role="ill",
uid="coauthor",
)
# create chapter
c1 = epub.EpubHtml(title="Intro", file_name="chap_01.xhtml", lang="hr")
c1.content = (
"<h1>Intro heading</h1>"
"<p>Zaba je skocila u baru.</p>"
'<p><img alt="[ebook logo]" src="static/ebooklib.gif"/><br/></p>'
)
# create image from the local image
image_content = open("ebooklib.gif", "rb").read()
img = epub.EpubImage(
uid="image_1",
file_name="static/ebooklib.gif",
media_type="image/gif",
content=image_content,
)
# add chapter
book.add_item(c1)
# add image
book.add_item(img)
# define Table Of Contents
book.toc = (
epub.Link("chap_01.xhtml", "Introduction", "intro"),
(epub.Section("Simple book"), (c1,)),
)
# add default NCX and Nav file
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())
# define CSS style
style = "BODY {color: white;}"
nav_css = epub.EpubItem(
uid="style_nav",
file_name="style/nav.css",
media_type="text/css",
content=style,
)
# add CSS file
book.add_item(nav_css)
# basic spine
book.spine = ["nav", c1]
# write to the file
epub.write_epub("test.epub", book, {})
```
# License
EbookLib is licensed under the `AGPL license <LICENSE.txt>`_.
# Authors
Full list of authors is in `AUTHORS.txt <AUTHORS.txt>`_ file.
Raw data
{
"_id": null,
"home_page": "https://github.com/SteveJob/ebooklib",
"name": "EbookLib-MD",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "ebook,epub,kindle",
"author": "Aleksandar Erkalovic",
"author_email": "aerkalov@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/50/97/ffa03593eb21caafd5a6393ec5e823bb08c730c366af8cf80dee099be826/EbookLib-MD-0.22.tar.gz",
"platform": null,
"description": "# About EbookLib\n\nEbookLib is a Python library for managing EPUB2/EPUB3 and Kindle files. It's capable of reading and writing EPUB files programmatically (Kindle support is under development).\n\nThe API is designed to be as simple as possible, while at the same time making complex things possible too. It has support for covers, table of contents, spine, guide, metadata and etc.\n\nEbookLib is used in `Booktype <https://github.com/sourcefabric/Booktype/>`_ from Sourcefabric, as well as `sprits-it! <https://github.com/the-happy-hippo/sprits-it>`_, `fanfiction2ebook <https://github.com/ltouroumov/fanfiction2ebook>`_, `viserlalune <https://github.com/vjousse/viserlalune>`_ and `Telemeta <https://github.com/Parisson/Telemeta>`_.\n\nPackages of EbookLib for GNU/Linux are available in `Debian <https://packages.debian.org/python-ebooklib>`_ and `Ubuntu <http://packages.ubuntu.com/python-ebooklib>`_. \n\nSphinx documentation is generated from the templates in the docs/ directory and made available at http://ebooklib.readthedocs.io\n\n# Usage\n\n## Reading\n```py\nimport ebooklib\nfrom ebooklib import epub\n\nbook = epub.read_epub('test.epub')\n\nfor image in book.get_items_of_type(ebooklib.ITEM_IMAGE):\n print(image)\n```\n\n\n## Writing\n```py\nfrom ebooklib import epub\n\nbook = epub.EpubBook()\n\n# set metadata\nbook.set_identifier(\"id123456\")\nbook.set_title(\"Sample book\")\nbook.set_language(\"en\")\n\nbook.add_author(\"Author Authorowski\")\nbook.add_author(\n \"Danko Bananko\",\n file_as=\"Gospodin Danko Bananko\",\n role=\"ill\",\n uid=\"coauthor\",\n)\n\n# create chapter\nc1 = epub.EpubHtml(title=\"Intro\", file_name=\"chap_01.xhtml\", lang=\"hr\")\nc1.content = (\n \"<h1>Intro heading</h1>\"\n \"<p>Zaba je skocila u baru.</p>\"\n '<p><img alt=\"[ebook logo]\" src=\"static/ebooklib.gif\"/><br/></p>'\n)\n\n# create image from the local image\nimage_content = open(\"ebooklib.gif\", \"rb\").read()\nimg = epub.EpubImage(\n uid=\"image_1\",\n file_name=\"static/ebooklib.gif\",\n media_type=\"image/gif\",\n content=image_content,\n)\n\n# add chapter\nbook.add_item(c1)\n# add image\nbook.add_item(img)\n\n# define Table Of Contents\nbook.toc = (\n epub.Link(\"chap_01.xhtml\", \"Introduction\", \"intro\"),\n (epub.Section(\"Simple book\"), (c1,)),\n)\n\n# add default NCX and Nav file\nbook.add_item(epub.EpubNcx())\nbook.add_item(epub.EpubNav())\n\n# define CSS style\nstyle = \"BODY {color: white;}\"\nnav_css = epub.EpubItem(\n uid=\"style_nav\",\n file_name=\"style/nav.css\",\n media_type=\"text/css\",\n content=style,\n)\n\n# add CSS file\nbook.add_item(nav_css)\n\n# basic spine\nbook.spine = [\"nav\", c1]\n\n# write to the file\nepub.write_epub(\"test.epub\", book, {})\n```\n\n\n# License\nEbookLib is licensed under the `AGPL license <LICENSE.txt>`_.\n\n\n# Authors\nFull list of authors is in `AUTHORS.txt <AUTHORS.txt>`_ file.\n",
"bugtrack_url": null,
"license": "GNU Affero General Public License",
"summary": "Ebook library which can handle EPUB2/EPUB3 and Kindle format",
"version": "0.22",
"project_urls": {
"Homepage": "https://github.com/SteveJob/ebooklib"
},
"split_keywords": [
"ebook",
"epub",
"kindle"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "af196074f06600646403c4dbdb88906edde680ea42c8509176f50338ea61930e",
"md5": "5aee68e166c569237f375fc96d4bbbe6",
"sha256": "6c9697a6ea84bb3ffc8f3c34ec52491740c0321cb83e998ae1ef0a2577b0beff"
},
"downloads": -1,
"filename": "EbookLib_MD-0.22-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5aee68e166c569237f375fc96d4bbbe6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 38927,
"upload_time": "2023-11-01T15:48:31",
"upload_time_iso_8601": "2023-11-01T15:48:31.795668Z",
"url": "https://files.pythonhosted.org/packages/af/19/6074f06600646403c4dbdb88906edde680ea42c8509176f50338ea61930e/EbookLib_MD-0.22-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5097ffa03593eb21caafd5a6393ec5e823bb08c730c366af8cf80dee099be826",
"md5": "313bc7ed8f1930cd359b02789ffa06d6",
"sha256": "439586f82e0bdabfd6aad514caf3bd98476bbbc42354416d20f99f61defb94df"
},
"downloads": -1,
"filename": "EbookLib-MD-0.22.tar.gz",
"has_sig": false,
"md5_digest": "313bc7ed8f1930cd359b02789ffa06d6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 115546,
"upload_time": "2023-11-01T15:48:33",
"upload_time_iso_8601": "2023-11-01T15:48:33.949464Z",
"url": "https://files.pythonhosted.org/packages/50/97/ffa03593eb21caafd5a6393ec5e823bb08c730c366af8cf80dee099be826/EbookLib-MD-0.22.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-01 15:48:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SteveJob",
"github_project": "ebooklib",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ebooklib-md"
}