libzim.reader
libzim reader module
- Archive to open and read ZIM files (gives access to all
Entry) - Entry knows about redirections, exposes path and title and gives access to
Item - Item holds the content and metadata
Usage:
with Archive(fpath) as zim:
entry = zim.get_entry_by_path(zim.main_entry.path)
print(f"Article {entry.title} at {entry.path} is "
f"{entry.get_item().content.nbytes}b")
Classes:
Functions:
-
get_cluster_cache_current_size–Get the current size of the cluster cache.
-
get_cluster_cache_max_size–Get the maximum size of the cluster cache.
-
set_cluster_cache_max_size–Set the size of the cluster cache.
Archive
ZIM Archive Reader
Parameters:
-
filename(Path) –Full path to a zim file.
Methods:
-
check–Whether Archive has a checksum and file verifies it.
-
get_entry_by_path–Retrieves an
Entryby its path. -
get_entry_by_title–Fetches an entry by title.
-
get_illustration_item–Get the illustration Metadata item of the archive.
-
get_illustration_sizes–Sizes for which an illustration is available (@1 scale only).
-
get_metadata–Retrieves the content of a metadata entry.
-
get_metadata_item–Get a Metadata's
Itemby name. -
get_random_entry–Get a random
Entry. -
has_entry_by_path–Whether Archive has an entry with this path.
-
has_entry_by_title–Checks if the archive contains an entry with the specified title.
-
has_illustration–Whether Archive has an illustration metadata for this size.
Attributes:
-
all_entry_count–Number of entries in Archive.
-
article_count–Number of “articles” in the Archive.
-
checksum–The checksum stored in the archive.
-
dirent_cache_current_size–Size of the dirent cache.
-
dirent_cache_max_size–Maximum size of the dirent cache.
-
entry_count–Number of user entries in Archive.
-
filename–Path of the ZIM Archive on the filesystem.
-
filesize–Total size of ZIM file (or sum of files if split).
-
has_checksum–Whether Archive includes a checksum of its content.
-
has_fulltext_index–Whether Archive includes a full-text index.
-
has_main_entry–Whether Archive has a main entry set.
-
has_new_namespace_scheme–Whether Archive is using new “namespaceless” namespace scheme.
-
has_title_index–Whether Archive includes a title index.
-
is_multipart–Whether Archive is multipart (split over multiple files).
-
main_entry–The main entry of the Archive.
-
media_count–Number of media in the Archive.
-
metadata_keys–List of Metadata keys present in this archive.
-
uuid–The uuid of the archive.
all_entry_count
property
all_entry_count
Number of entries in Archive.
Total number of entries in the archive, including internal entries created by libzim itself, metadata, indexes, etc.
Returns:
-
int–Number of entries in Archive.
article_count
property
article_count
Number of “articles” in the Archive.
If Archive has_new_namespace_scheme then this is the number of Entry with “FRONT_ARTICLE” Hint.
Otherwise, this is the number or entries in “A” namespace.
Note: a few ZIM created during transition might have new scheme but no listing, resulting in this returning all entries.
Returns:
-
int–Number of “articles” in the Archive.
checksum
property
checksum
dirent_cache_current_size
property
dirent_cache_current_size
dirent_cache_max_size
property
dirent_cache_max_size
entry_count
property
entry_count
Number of user entries in Archive.
If Archive doesn't support “user entries”
then this returns all_entry_count.
Returns:
-
int–Number of user entries in Archive.
filename
property
filename
Path of the ZIM Archive on the filesystem.
Returns:
-
Path–Path of the ZIM Archive on the filesystem.
filesize
property
filesize
Total size of ZIM file (or sum of files if split).
Returns:
-
int–Total size of ZIM file (or sum of files if split).
has_checksum
property
has_checksum
Whether Archive includes a checksum of its content.
The checksum is not the checksum of the file. It is an internal checksum stored in the zim file.
Returns:
-
bool–Whether Archive includes a checksum of its content.
has_fulltext_index
property
has_fulltext_index
Whether Archive includes a full-text index.
Returns:
-
bool–Whether Archive includes a full-text index.
has_main_entry
property
has_main_entry
has_new_namespace_scheme
property
has_new_namespace_scheme
Whether Archive is using new “namespaceless” namespace scheme.
Returns:
-
bool–Whether Archive is using new “namespaceless” namespace scheme.
has_title_index
property
has_title_index
is_multipart
property
is_multipart
Whether Archive is multipart (split over multiple files).
Returns:
-
bool–Whether Archive is multipart (split over multiple files).
main_entry
property
main_entry
media_count
property
media_count
metadata_keys
property
metadata_keys
uuid
property
uuid
The uuid of the archive.
Returns:
-
UUID–The uuid of the archive.
check
method descriptor
check() -> bool
Whether Archive has a checksum and file verifies it.
Returns:
-
bool–True if the file is valid, otherwise False.
get_entry_by_path
method descriptor
get_entry_by_title
method descriptor
Fetches an entry by title.
If ZIM doesn't contain a listing/titleOrdered/v1 entry (most likely
because if was created without any FRONT_ARTICLE) then this yields results
for matching path if the title was not set at creation time.
Parameters:
-
title(str) –The article title.
Returns:
-
Entry–The first Entry object matching the title.
Raises:
-
KeyError–If no entry with the provided title is found.
get_illustration_item
method descriptor
get_illustration_item(size: int = None) -> Item
get_illustration_sizes
method descriptor
get_illustration_sizes() -> Set[int]
Sizes for which an illustration is available (@1 scale only).
.. deprecated:: 3.8.0
Use :meth:get_illustration_infos instead for full illustration metadata
including width, height, and scale information.
Returns:
-
Set[int]–The set of available sizes of the illustration.
get_metadata
method descriptor
get_metadata_item
method descriptor
get_random_entry
method descriptor
get_random_entry() -> Entry
has_entry_by_path
method descriptor
has_entry_by_path(path: str) -> bool
Whether Archive has an entry with this path.
Returns:
-
bool–True if the archive has entry with this path, otherwise False.
has_entry_by_title
method descriptor
has_entry_by_title(title: str) -> bool
Checks if the archive contains an entry with the specified title.
This method relies on get_entry_by_title(), so its behavior applies here.
Parameters:
-
title(str) –The title of the entry.
Returns:
-
bool–True if an entry with the title exists, otherwise False.
has_illustration
method descriptor
has_illustration(size: int = None) -> bool
Whether Archive has an illustration metadata for this size.
Returns:
-
bool–True if the archive has an illustration metadata, otherwise False.
Entry
Entry in a ZIM archive.
Attributes:
-
*c_entry(Entry) –a pointer to the C++ entry object.
Methods:
-
get_item–Get the
Itemassociated with this entry. -
get_redirect_entry–Get the target entry if this entry is a redirect.
is_redirect
property
is_redirect
path
property
path
title
property
title
get_item
method descriptor
get_item() -> Item
Item
Item in a ZIM archive
Attributes:
*c_item (zim.Item): a pointer to the C++ Item object.
Attributes:
-
content–The data associated to the item.
-
mimetype–The mimetype of the item.
-
path–The UTF-8 decoded path of the item.
-
size–The size (in bytes) of the item.
-
title–The UTF-8 decoded title of the item.
content
property
content
path
property
path
title
property
title
get_cluster_cache_current_size
method descriptor
get_cluster_cache_current_size() -> int
Get the current size of the cluster cache.
Returns:
-
int–the current memory size (in bytes) used by the cluster cache.
get_cluster_cache_max_size
method descriptor
get_cluster_cache_max_size() -> int
Get the maximum size of the cluster cache.
Returns:
-
int–the maximum memory size used by the cluster cache (in bytes).
set_cluster_cache_max_size
method descriptor
set_cluster_cache_max_size(size_in_bytes: int)
Set the size of the cluster cache.
If the new size is lower than the number of currently stored clusters some clusters will be dropped from cache to respect the new size.
Parameters:
-
size_in_bytes(int) –the memory limit (in bytes) for the cluster cache.