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.1.tar.gz
(29.4 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.1.tar.gz.
File metadata
- Download URL: toolkitx-0.0.1.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36206ab86704bdb7d8478fc81278ba9bfd7d89728506db9772bd62ac8ead28b9
|
|
| MD5 |
1eb4640a990f693af9d971606ab59144
|
|
| BLAKE2b-256 |
09159e1366a7107c948c360d9e16923575a2bc4b69697fed5740ac46125e0508
|
File details
Details for the file toolkitx-0.0.1-py3-none-any.whl.
File metadata
- Download URL: toolkitx-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7658b01e0d2a1fcbeda6a26ea41c8870b2a4083fccbbf6644e383dcae1ad5d0d
|
|
| MD5 |
e5020a54af393d94523d6677d6dfebb1
|
|
| BLAKE2b-256 |
50e86d5de9d1fa5051cccaf4f4bd455bb74a30bfe4799c55b2b9dc944be382bc
|