Skip to main content

A personal Python toolkit for common tasks

Project description

toolkitx

A personal Python toolkit for common tasks. This package provides various utility functions to simplify common development workflows.

Features

  • Text Utilities (toolkitx.text_utils):
    • truncate_text_smart: Smartly truncates text by characters or words, with options for suffix and tolerance, attempting to preserve sentence or word boundaries.
    • split_text_by_word_count: Splits long text into overlapping chunks based on word count.
  • Command-Line Script:
    • hello: A simple script accessible via hello command after installation, prints a greeting message.
  • Experimental Translator (toolkitx.lab.translator):
    • Translator: A class providing translation capabilities using Baidu or Tencent translation APIs, with disk-based caching for performance. (Requires API credentials)

Installation

  1. Clone the repository:
    git clone https://github.com/ider-zh/toolkitx.git
    cd toolkitx
    
  2. Install the package. For development, you can install it in editable mode with development dependencies:
    pip install -e ".[dev]"
    
    For regular installation:
    pip install .
    

Usage

Text Utilities

from toolkitx import truncate_text_smart, split_text_by_word_count

# Smart Truncation
text = "This is a very long sentence that needs to be truncated."
truncated_char = truncate_text_smart(text, limit=20, mode="char", suffix="...")
print(f"Char truncated: {truncated_char}")

truncated_word = truncate_text_smart(text, limit=5, mode="word", suffix="...")
print(f"Word truncated: {truncated_word}")

# Split Text
long_text = "This is a long piece of text that we want to split into several smaller chunks with some overlap between them for context."
chunks = split_text_by_word_count(long_text, max_words=10, overlap=2)
for i, chunk in enumerate(chunks):
    print(f"Chunk {i+1}: {chunk}")

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

toolkitx-0.0.3.tar.gz (25.1 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.3-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toolkitx-0.0.3.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for toolkitx-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2747778d737ba1be9c5906369e0bc184f089e05ab5703544e416dae43ae16c17
MD5 74c8789ba6fc4c24356f0fcb36d8185d
BLAKE2b-256 4c81ad48ae65fcc3d2d896320bed33ba6debaa8badd3127889c1853123fc3910

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toolkitx-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for toolkitx-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 64d62ca9557b3f9ea68160189115a25748147ade065b082bf6426e345b237ba6
MD5 3b854b3b01f9c44e1e83015b4d89cec9
BLAKE2b-256 4e940fb4d22ec38b51329ae5b28e739a31b6fd77dc77f9136651c172ee388fc8

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