A high-level NLP toolkit built on top of modern LLMs.
Project description
TextTools
📌 Overview
TextTools is a high-level NLP toolkit built on top of modern LLMs.
It provides both sync (TheTool) and async (AsyncTheTool) APIs for maximum flexibility.
It provides ready-to-use utilities for translation, question detection, keyword extraction, categorization, NER extraction, and more - designed to help you integrate AI-powered text processing into your applications with minimal effort.
✨ Features
TextTools provides a rich collection of high-level NLP utilities, Each tool is designed to work with structured outputs (JSON / Pydantic).
categorize()- Classifies text into given categoriesextract_keywords()- Extracts keywords from textextract_entities()- Named Entity Recognition (NER) systemis_question()- Binary detection of whether input is a questiontext_to_question()- Generates questions from textmerge_questions()- Merges multiple questions with different modesrewrite()- Rewrites text with different wording/meaningsubject_to_question()- Generates questions about a specific subjectsummarize()- Text summarizationtranslate()- Text translation between languagespropositionize()- Convert text to atomic independence meaningful sentencescheck_fact()- Check whether a statement is relevant to the source textrun_custom()- Allows users to define a custom tool with an arbitrary BaseModel
📊 Tool Quality Tiers
| Status | Meaning | Use in Production? |
|---|---|---|
| ✅ Production | Evaluated, tested, stable. | Yes - ready for reliable use. |
| 🧪 Experimental | Added to the package but not fully evaluated. Functional, but quality may vary. | Use with caution - outputs not yet validated. |
Current Status
Production Tools:
categorize()(list mode)extract_keywords()extract_entities()is_question()text_to_question()merge_questions()rewrite()subject_to_question()summarize()run_custom()(fine in most cases)
Experimental Tools:
categorize()(tree mode)translate()propositionize()check_fact()run_custom()(not evaluated in all scenarios)
⚙️ with_analysis, logprobs, output_lang, user_prompt, temperature, validator and priority parameters
TextTools provides several optional flags to customize LLM behavior:
-
with_analysis: bool→ Adds a reasoning step before generating the final output. Note: This doubles token usage per call because it triggers an additional LLM request. -
logprobs: bool→ Returns token-level probabilities for the generated output. You can also specifytop_logprobs=<N>to get the top N alternative tokens and their probabilities.
Note: This feature works if it's supported by the model. -
output_lang: str→ Forces the model to respond in a specific language. The model will ignore other instructions about language and respond strictly in the requested language. -
user_prompt: str→ Allows you to inject a custom instruction or prompt into the model alongside the main template. This gives you fine-grained control over how the model interprets or modifies the input text. -
temperature: float→ Determines how creative the model should respond. Takes a float number from0.0to2.0. -
validator: Callable (Experimental)→ Forces TheTool to validate the output result based on your custom validator. Validator should return a bool (True if there were no problem, False if the validation fails.) If the validator fails, TheTool will retry to get another output by modifyingtemperature. You can specifymax_validation_retries=<N>to change the number of retries. -
priority: int (Experimental)→ Task execution priority level. Higher values = higher priority. Affects processing order in queues. Note: This feature works if it's supported by the model and vLLM.
Note: There might be some tools that don't support some of the parameters above.
🧩 ToolOutput
Every tool of TextTools returns a ToolOutput object which is a BaseModel with attributes:
result: Any→ The output of LLManalysis: str→ The reasoning step before generating the final outputlogprobs: list→ Token-level probabilities for the generated outputerrors: list[str]→ Any error that have occured during calling LLMToolOutputMetadata→tool_name: str→ The tool name which processed the inputprocessed_at: datetime→ The process timeexecution_time: float→ The execution time (seconds)
Note: You can use repr(ToolOutput) to see details of your ToolOutput.
🚀 Installation
Install the latest release via PyPI:
pip install -U hamtaa-texttools
🧨 Sync vs Async
| Tool | Style | Use case |
|---|---|---|
TheTool |
Sync | Simple scripts, sequential workflows |
AsyncTheTool |
Async | High-throughput apps, APIs, concurrent tasks |
⚡ Quick Start (Sync)
from openai import OpenAI
from texttools import TheTool
# Create your OpenAI client
client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
# Specify the model
model = "gpt-4o-mini"
# Create an instance of TheTool
the_tool = TheTool(client=client, model=model)
# Example: Question Detection
detection = the_tool.is_question("Is this project open source?", logprobs=True, top_logprobs=2)
print(detection.result)
print(detection.logprobs)
# Output: True + logprobs
# Example: Translation
translation = the_tool.translate("سلام، حالت چطوره؟" target_language="English", with_analysis=True)
print(translation.result)
print(translation.analysis)
# Output: "Hi! How are you?" + analysis
⚡ Quick Start (Async)
import asyncio
from openai import AsyncOpenAI
from texttools import AsyncTheTool
async def main():
# Create your AsyncOpenAI client
async_client = AsyncOpenAI(base_url="your_url", api_key="your_api_key")
# Specify the model
model = "gpt-4o-mini"
# Create an instance of AsyncTheTool
async_the_tool = AsyncTheTool(client=async_client, model=model)
# Example: Async Translation and Keyword Extraction
translation_task = async_the_tool.translate("سلام، حالت چطوره؟", target_language="English")
keywords_task = async_the_tool.extract_keywords("Tomorrow, we will be dead by the car crash")
(translation, keywords) = await asyncio.gather(translation_task, keywords_task)
print(translation.result)
print(keywords.result)
asyncio.run(main())
👍 Use Cases
Use TextTools when you need to:
- 🔍 Classify large datasets quickly without model training
- 🌍 Translate and process multilingual corpora with ease
- 🧩 Integrate LLMs into production pipelines (structured outputs)
- 📊 Analyze large text collections using embeddings and categorization
📚 Batch Processing
Process large datasets efficiently using OpenAI's batch API.
⚡ Quick Start (Batch)
from pydantic import BaseModel
from texttools import BatchJobRunner, BatchConfig
# Configure your batch job
config = BatchConfig(
system_prompt="Extract entities from the text",
job_name="entity_extraction",
input_data_path="data.json",
output_data_filename="results.json",
model="gpt-4o-mini"
)
# Define your output schema
class Output(BaseModel):
entities: list[str]
# Run the batch job
runner = BatchJobRunner(config, output_model=Output)
runner.run()
🤝 Contributing
Contributions are welcome!
Feel free to open issues, suggest new features, or submit pull requests.
🌿 License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 hamtaa_texttools-1.1.21.tar.gz.
File metadata
- Download URL: hamtaa_texttools-1.1.21.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e3272ef99214f5eca2615f4f6b529a1f8c98d5071d4bc1a946efca21d5bbe33
|
|
| MD5 |
a2095b3dc3da38c3d7626964071f409d
|
|
| BLAKE2b-256 |
0170560ea4bebf9fa7b192c9c3bd6c7f7ebe12feeff3b112ff39b9136a7fc54b
|
File details
Details for the file hamtaa_texttools-1.1.21-py3-none-any.whl.
File metadata
- Download URL: hamtaa_texttools-1.1.21-py3-none-any.whl
- Upload date:
- Size: 40.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abc74387e49b50c8551f5bbd9726d669e055dd937aaf5ca17238a164f4d114c5
|
|
| MD5 |
eae896419ea9657987fa63d5768a853d
|
|
| BLAKE2b-256 |
27c97cee7bb0a1a3d7ddd24d966ac74b9d7873913e6e9273a204c62d04b00cee
|