Skip to main content

Bound Book Format (BBF) tools and bindings

Project description

libbbf-python: Bound Book Format (BBF) Tools & Python Bindings

PyPI - Python Version PyPI License: MIT

Project Overview

libbbf-python provides Python bindings and command-line tools for the Bound Book Format (BBF). The Bound Book Format is an archive format designed for digital books and comics. This package allows Python developers to programmatically create and read .bbf files, and provides convenient command-line utilities to convert between common archive formats (like CBZ/CBX) and BBF.

The core of libbbf-python is a pybind11 wrapper around the high-performance C++ libbbf library, ensuring speed and native integration.

Features

  • libbbf Python Bindings: Access the full BBFBuilder (for creating BBF files) and BBFReader (for reading and extracting BBF files) functionality directly in Python.
  • cbx2bbf Command-Line Tool: Convert one or more CBZ/CBX archives (or directories of images) into a single .bbf file. Supports advanced features like custom page ordering, section markers (chapters, volumes), and metadata.
  • bbf2cbx Command-Line Tool: Extract the contents of a .bbf file back into a .cbz archive or an image directory. Supports integrity verification, section-specific extraction, and range extraction using keywords.
  • High Performance: Leverages C++ for core operations (file I/O, hashing, memory mapping) for optimal speed.
  • Integrity Checks: Built-in XXH3 hashing for robust data verification during creation and extraction.

Installation

You can install libbbf-python directly from PyPI:

pip install libbbf

Note on C++ Compiler: For platforms where pre-built binary wheels are not available (e.g., specific Linux distributions or older Python versions), pip will attempt to build the package from source. This requires a C++ compiler (like GCC/Clang on Linux/macOS or MSVC on Windows) to be installed on your system.

Command-Line Tools Usage

Once installed, two command-line tools will be available globally: cbx2bbf and bbf2cbx.

cbx2bbf: Create BBF Files from CBZ/Images

Usage:

cbx2bbf <inputs...> [options] --output <output.bbf>

Inputs: Can be individual image files (.png, .avif, .jpg), directories containing images, or .cbz/.cbx archives.

Options:

  • --output <output.bbf>, -o <output.bbf>: Required. Specifies the output BBF filename.
  • --order <path.txt>: Use a text file to define page order. Format: filename:index (e.g., cover.png:1, credits.png:-1 for last page).
  • --sections <path.txt>: Use a text file to define multiple sections. Format: Name:Target[:Parent].
  • --section "Name:Target[:Parent]": Add a single section marker. Target can be a 1-based page index or a filename. Example: --section "Chapter 1:001.png" or --section "Volume 1:my_comic.cbx:Series".
  • --meta "Key:Value": Add archival metadata (e.g., --meta "Title:Akira").

Examples:

  1. Basic Conversion:

    cbx2bbf my_comic.cbz -o output.bbf
    
  2. Converting Multiple CBZs with Sections and Metadata:

    cbx2bbf vol1.cbz vol2.cbz \
        --section "Volume 1:vol1.cbz" \
        --section "Volume 2:vol2.cbz" \
        --meta "Title:My Awesome Series" \
        --meta "Author:Me" \
        -o series.bbf
    

    (Note: vol1.cbz and vol2.cbz as targets will automatically map to the first page of those archives after sorting)

  3. Converting a Directory of Images with a Custom Order File:

    # pages.txt content:
    # cover.png:1
    # page001.png:2
    # ...
    # credits.png:-1
    
    cbx2bbf ./my_pages_folder/ --order pages.txt -o my_book.bbf
    

bbf2cbx: Extract BBF Files

Usage:

bbf2cbx <input.bbf> [options] --output <output.cbz_or_dir>

Options:

  • --output <output_path>, -o <output_path>: Required. Output .cbz file or directory name.
  • --dir: Extract to a directory instead of a .cbz archive.
  • --section "Name": Extract only a specific section defined in the BBF.
  • --rangekey "String": When extracting a section, find the end of extraction by matching this string against the next section's title. Useful for extracting "Vol 1" until "Vol 2" begins.
  • --verify: Perform a full XXH3 integrity check on all assets and the directory hash before extraction.
  • --info: Display book structure and metadata without extracting.

Examples:

  1. Extract entire BBF to CBZ with Verification:

    bbf2cbx my_book.bbf -o my_book_extracted.cbz --verify
    
  2. Extract a specific section to a folder:

    bbf2cbx series.bbf --section "Volume 1" --dir -o ./output/vol1/
    
  3. Extract a range using rangekey:

    bbf2cbx series.bbf --section "Volume 1" --rangekey "Volume 2" -o vol1_only.cbz
    
  4. Display BBF Information:

    bbf2cbx series.bbf --info
    

Using libbbf

You can also interface libbbf directly from python.

Example 1: Creating a .bbf file

from libbbf import BBFBuilder
import os

# Create a new Bound Book
builder = BBFBuilder("my_comic.bbf")

# Add Metadata
builder.add_metadata("Title", "Solo Leveling")
builder.add_metadata("Author", "Chugong")

# Add Pages (Assets are automatically deduplicated by hash!)
page_files = sorted(os.listdir("./chapter_images"))
for i, filename in enumerate(page_files):
    full_path = os.path.join("./chapter_images", filename)
    
    # Flags: 0 = Standard
    builder.add_page(full_path, type=1, flags=0) 

    # Define a Chapter every 20 pages
    if i % 20 == 0:
        builder.add_section(f"Chapter {i // 20 + 1}", start_page=i)

# Finalize writes the footer and optimized tables
builder.finalize()
print("BBF created successfully.")

Example 2: Verifying a .bbf file

import libbbf
import time

reader = libbbf.BBFReader("massive_archive.bbf")

print("Verifying file integrity...")
start = time.time()

# This releases the GIL, so it's thread-safe and incredibly fast
is_valid = reader.verify()

end = time.time()

if is_valid:
    print(f"SUCCESS: Integrity verified in {end - start:.4f}s")
else:
    print("ERROR: Corruption detected!")

Contributing

Contributions, issues, and feature requests are welcome! For libbbf, free to check the issues page (or create one if it doesn't exist yet).

License

This project is licensed under the MIT License - see the LICENSE file for details.


Project details


Download files

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

Source Distribution

libbbf-0.2.13.tar.gz (87.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libbbf-0.2.13-cp312-cp312-win_amd64.whl (126.0 kB view details)

Uploaded CPython 3.12Windows x86-64

libbbf-0.2.13-cp312-cp312-win32.whl (118.5 kB view details)

Uploaded CPython 3.12Windows x86

libbbf-0.2.13-cp312-cp312-musllinux_1_1_x86_64.whl (693.8 kB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

libbbf-0.2.13-cp312-cp312-musllinux_1_1_i686.whl (775.3 kB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ i686

libbbf-0.2.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (184.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

libbbf-0.2.13-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (213.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

libbbf-0.2.13-cp312-cp312-macosx_11_0_arm64.whl (130.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

libbbf-0.2.13-cp312-cp312-macosx_10_9_x86_64.whl (138.0 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

libbbf-0.2.13-cp311-cp311-win_amd64.whl (124.7 kB view details)

Uploaded CPython 3.11Windows x86-64

libbbf-0.2.13-cp311-cp311-win32.whl (118.0 kB view details)

Uploaded CPython 3.11Windows x86

libbbf-0.2.13-cp311-cp311-musllinux_1_1_x86_64.whl (694.5 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

libbbf-0.2.13-cp311-cp311-musllinux_1_1_i686.whl (775.1 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ i686

libbbf-0.2.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (185.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

libbbf-0.2.13-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (214.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

libbbf-0.2.13-cp311-cp311-macosx_11_0_arm64.whl (129.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

libbbf-0.2.13-cp311-cp311-macosx_10_9_x86_64.whl (136.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

Details for the file libbbf-0.2.13.tar.gz.

File metadata

  • Download URL: libbbf-0.2.13.tar.gz
  • Upload date:
  • Size: 87.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.12

File hashes

Hashes for libbbf-0.2.13.tar.gz
Algorithm Hash digest
SHA256 0250f97b5ff98b78aa6114a394cc27246b4926e43bb19a6db34ba8fa86609a4a
MD5 d37d84084b7a9b6ff3acd8d013e49587
BLAKE2b-256 b59c03a64b631b2c72495a94bdd1fcb65da9064bcac60fafa7357d5a3d83e51f

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: libbbf-0.2.13-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 126.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.12

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3610b9620ebb099cfa911431a66e26c4306ea4b0d1b93a2e1294ebf8e0d3348c
MD5 9d72fbe64191b94ac5636d872044b61c
BLAKE2b-256 e2f7d1ef0cf552a3b8d9812f3e230f8ba31e32c6066337669dd1e443f1299944

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-win32.whl.

File metadata

  • Download URL: libbbf-0.2.13-cp312-cp312-win32.whl
  • Upload date:
  • Size: 118.5 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.12

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 d6b07b6a83e436947c06e85e7037a0af7692747039dafe7dee688d2db1fd907b
MD5 48c3bf7b4bcc69a9e31352d7cd1c4216
BLAKE2b-256 50de3e43763318cd25e3c722915c9276ce8bd2ec42eddccd154564aeb69614ef

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ad57ca9cd6b37cff113dbef0fe1790ac390dd8134a1af8cd7e63d61f7809cf8d
MD5 f76e3168331a02d6e7ee1486fb5e1d1f
BLAKE2b-256 aef42acf47cd5ce695b0a5d1e9f9819199862a74e02fefb060ff748aa9e86201

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 6d8435a82fed722dec9c6411f810c3000e33aeb1f313a245f4502a6bc2ca928d
MD5 95715c3db8a4fe23d16624af1502aa18
BLAKE2b-256 44ce67725f7d100b45a59e0d3dc957b0dc86282fb28ef9ef10f4c78f397640d5

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c060e825089c19779007125fa57b3af013d88e2d8629640f169dd97235b399fb
MD5 14191ee1f5c0af3f31f2d2e15d11ab4a
BLAKE2b-256 9135f23ef1754701e35d78fc4845c8684beccefad543aa7d6423cad441c56098

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 eb93e862af2c6477157f736599912868f8c3002d43adf7538ebd3c86a55713b6
MD5 2ab7ef71333192fce7a38f1dedd4782a
BLAKE2b-256 a41e83943e4b5dcc662a577cb3cac2a384de95151e01e7e65f3951f832f4683d

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c5e8361d0df39938f08a9a8fa2a770f1329e1227b5778a9026ce394839daf48
MD5 f346cecba38c248dcc3dba26984a8fcf
BLAKE2b-256 a5188e6b294a526d574587c84fb2776e7a869d474188b3c1921d378799f75131

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 58e85aba4bb0ca6b446aa1f7eec3d416e658e0f386904f11b63bd8570e722e3a
MD5 edd325cb890246fa6c6306d287483cbe
BLAKE2b-256 5a56e13d5ef37df851f96331a9d74a12d3793e30e0fd96e2b063647085c723ab

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: libbbf-0.2.13-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 124.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.12

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 04530cd4b50d5dbeb77a539ce63a2d85af18a91cef20e2e3cbdd0fe71395d3b0
MD5 22fca0a142c12b226d8a8b1013aaabd6
BLAKE2b-256 1511b51b79b073a3af2a0e4a65b60fb7027acb2a18cb60a324667863675616b1

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-win32.whl.

File metadata

  • Download URL: libbbf-0.2.13-cp311-cp311-win32.whl
  • Upload date:
  • Size: 118.0 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.12

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 31d0214d27752260d8ffb10797a899bef915da316164f7b7aaf7a1a201f3e1bc
MD5 2b1f824a106ce2e993a324e907932ae7
BLAKE2b-256 88169b66c739d92b3ea5bed6db6c7fe2f4c1b5bbc6ea5bef8a70eba0fa56ad87

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 dd805cc91c7e02fe786f22218161e5056210d91bdfc2215f709cc307f69fa282
MD5 9aec5ab051792be7fc2943665a0066d6
BLAKE2b-256 00a4f89d6d1959842a1f6cf4453ce6fb55ba96a826660f86e5b9b6e650ac04b4

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 e7fef8d95ef16454d9a6145b4152f5e7adfbe196f53ca71d0c3a12a8de707be0
MD5 a3b24c23be53aec9cb8f12209a25c113
BLAKE2b-256 167b19d12574a2a5da007842640a3540fb535b45e97fae57a57bedccd0abea3e

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c36a0e712e1d2ad22efc3723ab5c18efe16b88c40b40e3d5939a93a0affee6f
MD5 48f51e8df49ff0630ca2c88249e2c68b
BLAKE2b-256 78f6b25d4c528960842f4c55825a81a4d1f6535ae70aea8c3427e324c08b703e

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 69d3843ed51405005028553d86092cc9f34a5fa4406f2c49932e224673c656ad
MD5 5c76201159e653e44e85d050fe08e4c1
BLAKE2b-256 7500d6da486a787ef271c475e2e65818b9394b7e9f9956a35f95bcc155f3bfdd

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4942442ebb0e306084755019315b7c4aa311114e63284d95105aacb9a6fbf031
MD5 069903664cd86dd580360c91ffc62cfb
BLAKE2b-256 4a2b283b125b0cc88c650c3370b6c047c15274143b21ab3474db7384730f174b

See more details on using hashes here.

File details

Details for the file libbbf-0.2.13-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for libbbf-0.2.13-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 818499c1c06c4dc8e59529c10dd5a6a5e990cb089d493f83124f657011df1f0c
MD5 827a4f162370fcb8221ed9afa38984a3
BLAKE2b-256 323b4406fe34f420b089e5b3993a54b04bec0c178aca6e1b56448c77fabc4631

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page