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.
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
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"))
See example for a basic usage of the writer API.
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"