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 viahellocommand 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
- Clone the repository:
git clone https://github.com/ider-zh/toolkitx.git cd toolkitx
- 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.2.tar.gz
(30.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toolkitx-0.0.2.tar.gz.
File metadata
- Download URL: toolkitx-0.0.2.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
230a3fcf72c1270ab1e48435b336a3554a94f403d4281168f91e0108264c1694
|
|
| MD5 |
31d27b5fd804aff823fb7e660a83ab82
|
|
| BLAKE2b-256 |
22176dcb3504074e3a6a4991d3a889390fa3de3abace05bcedc2aa496507a119
|
File details
Details for the file toolkitx-0.0.2-py3-none-any.whl.
File metadata
- Download URL: toolkitx-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4cebcd6b888c80645012ebf4f122c079be1ddbeeedc0ba3e6e9d565a88d16f0
|
|
| MD5 |
a402996112ada719430a73182bc42f54
|
|
| BLAKE2b-256 |
97d8dabe92141fa3ad51ab78c52c616b0c711b7308d1eb7889032e52121d178d
|