book_to_skill Config.py Configuration Parameters: A Complete Reference

The config.py module in the virgiliojr94/book-to-skill repository centralizes runtime constants that control output directories, token estimation ratios, supported file extensions, and Python dependency mappings.

Managing document extraction pipelines requires consistent runtime configuration. The book-to-skill open-source tool uses book_to_skill/config.py as its single source of truth for path management, file type validation, and dependency tracking. Understanding these configuration parameters allows you to customize extraction behavior and integrate the tool into automated workflows.

Output Directory and File Path Configuration

The output parameters define where the extractor stores intermediate artifacts during processing.

  • OUTPUT_DIR: A Path object specifying the working directory for each extraction run. By default, this resolves to a temporary per-process directory named book_skill_work-<PID>. You can override this location by setting the BOOK_SKILL_WORKDIR environment variable before running the tool.
  • OUTPUT_TEXT: A Path object pointing to full_text.txt, the raw text dump produced by the extractor.
  • OUTPUT_META: A Path object pointing to metadata.json, the structured JSON file containing extracted metadata such as title, authors, and table of contents.

In book_to_skill/cli.py, the CLI constructs the output directory using config.OUTPUT_DIR, ensuring that each invocation writes to the correct location.

Token Estimation Parameters

Accurate token counting is essential for cost estimation and context window management. The configuration defines language-specific ratios used by the utility functions in book_to_skill/utils.py.

  • WORDS_PER_TOKEN (default: 0.75): Approximate number of words comprising a single token for Latin-based text (e.g., English, Spanish, French).
  • CJK_CHARS_PER_TOKEN (default: 0.5): Approximate number of characters corresponding to one token for Chinese, Japanese, and Korean (CJK) languages that do not use whitespace delimiters.

The estimate_tokens() helper in utils.py references these constants to calculate token counts without requiring external API calls.

File Type Support and Extension Whitelists

The extractor validates input files against predefined extension sets to determine which parser to invoke.

  • TEXT_EXTENSIONS: A set[str] of extensions treated as plain text (e.g., .txt, .md).
  • HTML_EXTENSIONS: A set[str] triggering HTML parsing logic.
  • CALIBRE_EBOOK_EXTENSIONS: A set[str] recognized by Calibre-based ebook handling routines.
  • SUPPORTED_EXTENSIONS: The master whitelist combining PDF, EPUB, DOCX, RTF, and the above categories. The extractor in scripts/extract.py checks this set to validate inputs before processing.

Python Dependency Mapping

The PYTHON_DEPENDENCIES dictionary maps logical library names to their pip package identifiers (e.g., "pymupdf": "PyMuPDF"). Before processing a document, the extractor checks this mapping to ensure required third-party tools are installed, preventing mid-process failures due to missing dependencies.

Practical Usage Examples

Writing Extraction Results Using Config Paths

from book_to_skill import config
import json

def write_results(text: str, metadata: dict) -> None:
    # Ensure the output directory exists

    config.OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
    
    # Write the raw extracted text

    config.OUTPUT_TEXT.write_text(text, encoding="utf-8")
    
    # Write the JSON metadata

    config.OUTPUT_META.write_text(
        json.dumps(metadata, indent=2), 
        encoding="utf-8"
    )

print(f"Results saved in {config.OUTPUT_DIR}")

Validating Supported File Extensions

from pathlib import Path
from book_to_skill import config

def is_supported(file_path: Path) -> bool:
    return file_path.suffix.lower() in config.SUPPORTED_EXTENSIONS

print(is_supported(Path("example.pdf")))   # → True

print(is_supported(Path("image.png")))     # → False

Estimating Token Counts

from book_to_skill import utils, config

text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
tokens = utils.estimate_tokens(text)   # uses WORDS_PER_TOKEN / CJK_CHARS_PER_TOKEN

print(f"Estimated tokens: {tokens}")

Summary

  • OUTPUT_DIR controls where extraction artifacts are stored and can be overridden via the BOOK_SKILL_WORKDIR environment variable.
  • WORDS_PER_TOKEN and CJK_CHARS_PER_TOKEN enable accurate token counting for Latin-based and CJK languages respectively.
  • SUPPORTED_EXTENSIONS acts as the master whitelist that determines valid input file types across the pipeline.
  • PYTHON_DEPENDENCIES ensures required third-party libraries are available before document processing begins.
  • These parameters are accessed throughout the codebase, including book_to_skill/cli.py for path construction and book_to_skill/utils.py for token estimation.

Frequently Asked Questions

How do I change the default output directory in book_to_skill?

Set the BOOK_SKILL_WORKDIR environment variable before running the tool. Alternatively, modify the OUTPUT_DIR constant directly in book_to_skill/config.py at line 27, though environment variables are preferred for deployment flexibility.

What file formats does book_to_skill support?

The tool accepts PDF, EPUB, DOCX, and RTF files, plus plain text and HTML formats as defined in SUPPORTED_EXTENSIONS. This master set combines TEXT_EXTENSIONS, HTML_EXTENSIONS, and CALIBRE_EBOOK_EXTENSIONS to determine valid inputs.

How does book_to_skill estimate token counts for different languages?

The utility functions in book_to_skill/utils.py use WORDS_PER_TOKEN (approximately 0.75 words per token) for Latin-based languages and CJK_CHARS_PER_TOKEN (approximately 0.5 characters per token) for Chinese, Japanese, and Korean text. This allows approximate token counting without API calls.

Where does book_to_skill check for required Python dependencies?

The PYTHON_DEPENDENCIES dictionary in book_to_skill/config.py (lines 47-56) maps logical library names to pip package names. The extraction pipeline validates these dependencies before processing to ensure tools like PyMuPDF are installed.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →