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.

Metadata

Release files for toolkitx 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for toolkitx 0.0.7
File Size Uploaded
toolkitx-0.0.7.tar.gz 86.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for toolkitx 0.0.7
File Interpreter ABI Platform
toolkitx-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 108.5 kB

Release files / toolkitx-0.0.7.tar.gz

Download URL toolkitx-0.0.7.tar.gz
Size 86.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6a068b4e4f3a44a1583386f78759fd4da1c8c23a79dc1b5664197d939ccc2a20
BLAKE2b-256 checksum
How to use checksums
172efea1ec3b1428040547b00a22ceffd515f3c196f1bb8cf92b3f01970ffc26
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / toolkitx-0.0.7-py3-none-any.whl

Download URL toolkitx-0.0.7-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21081f68e10f9adbb7d2c79b9186503eca6d9d6fbc7be3654efada7de78b5580
BLAKE2b-256 checksum
How to use checksums
bcc800b092e0e64d5fdae9b5eca97c0eaa98f66cd2320fa64dae846a32015016
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page