Skip to main content

ToolkitX

Documentation Status License: MIT Python 3.12+

A personal Python toolkit for common tasks. This package provides robust utility functions to simplify common development workflows, focusing on text processing, HTML conversion, and task resilience.

📖 Full Documentation: https://toolkitx.readthedocs.io/en/latest/

Features

  • HTML Utilities (toolkitx.html_utils):

    • html_to_markdown: Robust HTML to Markdown conversion. Handles complex tables (colspan/rowspan) by expansion and serializes nested tables to JSON for better LLM/Agent understanding. Automatically promotes the first row to header if missing.
  • Text Utilities (toolkitx.text_utils):

    • truncate_text_smart: Smartly truncates text by characters or words, attempting to preserve sentence or word boundaries with configurable tolerance.
    • split_text_by_word_count: Splits long text into overlapping chunks based on word count.
  • Task Utilities (toolkitx.task_utils):

    • with_resilience: A decorator for API resilience with rate limiting (QPS), exponential backoff retry, and jitter.
    • PersistentTaskQueue: A persistent task queue with SQLite backend, supporting concurrent processing, automatic retry, crash recovery, and graceful shutdown.
  • Experimental Translator (toolkitx.lab.translator):

    • Translator: A class providing translation capabilities using Baidu or Tencent translation APIs, with disk-based caching.

Installation

We recommend using uv for fast and reliable dependency management.

# Clone the repository
git clone https://github.com/ider-zh/toolkitx.git
cd toolkitx

# Install with development dependencies
uv pip install -e ".[dev,docs]"

Usage

HTML to Markdown (Robust Table Support)

from toolkitx import html_to_markdown

# Handles merged cells (colspan/rowspan) and nested tables
html = """
<table>
  <tr><td colspan="2">Merged Header</td></tr>
  <tr><td>Cell 1</td><td>Cell 2</td></tr>
  <tr>
    <td>Outer</td>
    <td>
      <table><tr><td>Nested</td></tr></table>
    </td>
  </tr>
</table>
"""

md = html_to_markdown(html)
print(md)

Text Smart Truncation

from toolkitx import truncate_text_smart

text = "Hello World. This is a long sentence that should be truncated smartly."
# Strips trailing punctuation automatically
truncated = truncate_text_smart(text, limit=12) 
print(truncated) # Output: 'Hello World...'

Task Resilience Decorator

from toolkitx import with_resilience

@with_resilience(qps=2.0, max_retries=3)
def fetch_data(url):
    # This function will be rate-limited and retried automatically
    pass

Development

Running Tests

# Run unit tests
make test

# Run documentation tests (verify examples in docstrings)
make test-docs

Documentation

# Preview documentation locally
make docs-serve

# Build static documentation site
make docs-build

Changelog

v0.0.7 (2026-07-09)

  • Bug Fix: html_to_markdown no longer crashes (IndexError: list index out of range) when expanding tables that contain empty cells (e.g. <td rowspan="2"></td>). Empty cells now render as zero-width placeholders while preserving colspan/rowspan expansion.

v0.0.6 (2026-07-09)

  • Dependency: Pinned tencentcloud-sdk-python to <3.1.106. The Tencent SDK removed the TMT TextTranslate API (incl. TextTranslateRequest) starting in 3.1.106, which would break toolkitx.lab.translator. The text-translation engine now stays on the last compatible release.

v0.0.5 (2026-05-30)

  • New Feature: Added html_utils with robust html_to_markdown converter.
  • Improved: truncate_text_smart now strips trailing punctuation before appending suffix.
  • Documentation: Established full automated documentation system with MkDocs, Material theme, and Read the Docs integration.
  • Verifiable Docs: Added doctest examples to all core functions and a make test-docs target.
  • Workflow: Integrated ruff for linting and formatting.
  • Dependency Management: Fully transitioned to uv and pinned mkdocs for stability.

v0.0.4 (2026-03-07)

  • Added task_utils module with with_resilience decorator and PersistentTaskQueue.
  • Added polars, pydantic, and tqdm as dependencies.

Download files

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

Source Distribution

toolkitx-0.0.7.tar.gz (86.8 kB view details)

Uploaded Source

Built Distribution

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

toolkitx-0.0.7-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file toolkitx-0.0.7.tar.gz.

File metadata

  • Download URL: toolkitx-0.0.7.tar.gz
  • Upload date:
  • Size: 86.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for toolkitx-0.0.7.tar.gz
Algorithm Hash digest
SHA256 6a068b4e4f3a44a1583386f78759fd4da1c8c23a79dc1b5664197d939ccc2a20
MD5 058f56b4b9ad1d765818ac632157418b
BLAKE2b-256 172efea1ec3b1428040547b00a22ceffd515f3c196f1bb8cf92b3f01970ffc26

See more details on using hashes here.

File details

Details for the file toolkitx-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: toolkitx-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for toolkitx-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 21081f68e10f9adbb7d2c79b9186503eca6d9d6fbc7be3654efada7de78b5580
MD5 940b15dc2f40a1efe5c990a2ad0f491d
BLAKE2b-256 bcc800b092e0e64d5fdae9b5eca97c0eaa98f66cd2320fa64dae846a32015016

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 Sentry Error logging StatusPage Status page