Skip to content

Latest commit

 

History

History
72 lines (52 loc) · 2.59 KB

README.md

File metadata and controls

72 lines (52 loc) · 2.59 KB

python-libzim

The Python-libzim package allows you to read/write ZIM files in Python. It provides a shallow Python interface on top of the libzim C++ library.

It is primarily used in openZIM scrapers like for example Sotoki or Youtube2zim.

Read CONTRIBUTING.md to know more about Python-libzim development.

Build Status CodeFactor License: GPL v3 PyPI version shields.io codecov

Installation

The PyPI package is bundled with a recent version of the libzim for macOS and GNU/Linux (x86_64 architecture). For other OSes, the latest libzim has to be compiled manually, See Setup hints to know more.

pip3 install libzim

Quickstart

Read a ZIM

from libzim.reader import Archive

zim = Archive("test.zim")
print(f"Main entry is at {zim.main_entry.get_item().path}")
entry = zim.get_entry_by_path("path/to/my-article")
print(f"Entry {entry.title} at {entry.path} is {entry.get_item().size}b:")
print(bytes(entry.get_item().content).decode("UTF-8"))

Write a ZIM

See example for a basic usage of the writer API.

Setup hints

Installing the libzim dylib and headers manually

If you have to install the libzim manually, you will have to compile libzim from source. This binding has been designed to work with the latest version of the libzim, we only recommend to use it with latest released version.

If you have not installed libzim in standard directory, you will have to set LD_LIBRARY_PATH to allow python to find the library. Assuming you have extracted (or installed) the library if LIBZIM_DIR:

export LD_LIBRARY_PATH="${LIBZIM_DIR}/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"

License

GPLv3 or later, see LICENSE for more details.