Skip to main content

A python-facing API for creating and interacting with ZIM files

Project description

python-libzim

The Python bindings for libzim.

# Install from PyPI: https://pypi.org/project/libzim/
pip3 install libzim

This library allows you to interact with .zim files via Python.

It just provides a shallow Python interface on top of the libzim C++ library (maintained by OpenZIM).

It is primarily used by sotoki.

Quickstart

Reader API

from libzim.reader import File

f = File("test.zim")
article = f.get_article("article/url.html")
print(article.url, article.title)
if not article.is_redirect():
    print(article.content)

Write API

See example for a basic usage of the writer API.


User Documentation

Setup: Ubuntu/Debian x86_64 (Recommended)

Install the python libzim package from PyPI.

pip3 install libzim

The x86_64 linux wheel automatically includes the libzim.so dylib and headers, but other platforms may need to install libzim and its headers manually.

Installing the libzim dylib and headers manually

If you are not on a linux x86_64 platform, you will have to install libzim manually.

Either by get a prebuilt binary at https://download.openzim.org/release/libzim or compile libzim from source.

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"

Setup: Docker (Optional)

docker build . --tag openzim:python-libzim

# Run a custom script inside the container
docker run -it openzim:python-libzim ./some_example_script.py

# Or use the python repl interactively
docker run -it openzim:python-libzim
>>> import libzim

Developer Documentation

These instructions are for developers working on the python-libzim source code itself. If you are simply a user of the library and you don't intend to change its internal source code, follow the User Documentation instructions above instead.

Setup: Ubuntu/Debian

Note: Make sure you've installed libzim dylib + headers first (see above).

apt install coreutils wget git ca-certificates \
        g++ pkg-config libtool automake autoconf make meson ninja-build \
        liblzma-dev zlib1g-dev libicu-dev libgumbo-dev libmagic-dev

pip3 install --upgrade pip pipenv

export CFLAGS="-I${LIBZIM_DIR}/include"
export LDFLAGS="-L${LIBZIM_DIR}/lib/x86_64-linux-gnu"
git clone https://github.com/openzim/python-libzim
cd python-libzim
python setup.py build_ext
pipenv install --dev
pipenv run pip install -e .

Setup: Docker

docker build . -f Dockerfile.dev --tag openzim:python-libzim-dev

docker run -it openzim:python-libzim-dev ./some_example_script.py

docker run -it openzim:python-libzim-dev
$ black . && flake8 . && pytest .
$ pipenv install --dev <newpackagehere>
$ python setup.py build_ext
$ python setup.py sdist bdist_wheel
$ python setup.py install
$ python -c "import libzim"

Common Tasks

Run Linters & Tests

# Autoformat code with black
black --exclude=setup.py .
# Lint and check for errors with flake8
flake8 --exclude=setup.py .
# Typecheck with mypy (optional)
mypy .
# Run tests
pytest .

Rebuild Cython extension during development

rm libzim/libzim.cpp
rm -Rf build
rm -Rf *.so
python setup.py build_ext
python setup.py install

Build package sdist and bdist_wheels for PyPI

python setup.py build_ext
python setup.py sdist bdist_wheel

# upload to PyPI (caution: this is done automatically via Github Actions)
twine upload dist/*

Use a specific libzim dylib and headers when compiling python-libzim

export CFLAGS="-I${LIBZIM_DIR}/include"
export LDFLAGS="-L${LIBZIM_DIR}/lib/x86_64-linux-gnu"
export LD_LIBRARY_PATH="${LIBZIM_DIR}/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
python setup.py build_ext
python setup.py install

Further Reading

Related Projects

Research

Debugging

Packaging

Download files

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

Source Distribution

libzim-0.0.2.tar.gz (93.6 kB view details)

Uploaded Source

Built Distributions

libzim-0.0.2-cp38-cp38-manylinux1_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.8

libzim-0.0.2-cp37-cp37m-manylinux1_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.7m

libzim-0.0.2-cp36-cp36m-manylinux1_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.6m

File details

Details for the file libzim-0.0.2.tar.gz.

File metadata

  • Download URL: libzim-0.0.2.tar.gz
  • Upload date:
  • Size: 93.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for libzim-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a29d24d7f065f7a5771e5ae049d32f90a23bdde4912daa33bad47f43269d75f3
MD5 e9f89d0e4d4ba6ae5e29819f92a6e1cb
BLAKE2b-256 16f63a4b866d309d57644a2047d687b0efa42b45ed4df5a994b5459f0d2e3ed9

See more details on using hashes here.

File details

Details for the file libzim-0.0.2-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: libzim-0.0.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for libzim-0.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b71d789e56167d103c3b17eda3eb9e9f03f9bcddf355a373fc3e6d1f518aae2e
MD5 29d184eb4c1bde9856d5d8160284c0c5
BLAKE2b-256 a7bcbecca6cdfd56a0bc67507bd69fc38f10e4c35933bad898696db2eb8c50f5

See more details on using hashes here.

File details

Details for the file libzim-0.0.2-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: libzim-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for libzim-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 658bee6f2232f028dc809d72c75768fd5c4b80f063129c4a953f2905009fa717
MD5 dcd3b99b5622b04b6afdb3ed8cc5065d
BLAKE2b-256 8db33d64f83cbfa407b2983fc9a7cac6baf1060513e3285036a297f0dd841e24

See more details on using hashes here.

File details

Details for the file libzim-0.0.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: libzim-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 7.6 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for libzim-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b4a05fa97bb19003feb94c9e852240f3e1ce31ce03b5235808267c9dea852523
MD5 737175a7d851239f77150bbae35e3e74
BLAKE2b-256 e0a98134a01bc37040733fd5a8248c8d96ccee0ec89c78407c335e597ab27c27

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