Skip to main content

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 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.

Note: Most features of texttools are reliable when you use google/gemma-3n-e4b-it model.


✨ Features

TextTools provides a rich collection of high-level NLP utilities, Each tool is designed to work with structured outputs.

  • categorize() - Classifies text into given categories
  • extract_keywords() - Extracts keywords from the text
  • extract_entities() - Named Entity Recognition (NER) system
  • is_question() - Binary question detection
  • text_to_question() - Generates questions from text
  • merge_questions() - Merges multiple questions into one
  • rewrite() - Rewrites text in a diffrent way
  • subject_to_question() - Generates questions about a specific subject
  • summarize() - Text summarization
  • translate() - Text translation
  • propositionize() - Convert text to atomic independence meaningful sentences
  • check_fact() - Check whether a statement is relevant to the source text
  • run_custom() - Allows users to define a custom tool with an arbitrary BaseModel

🚀 Installation

Install the latest release via PyPI:

pip install -U hamtaa-texttools

📊 Tool Quality Tiers

Status Meaning Tools Use in Production?
✅ Production Evaluated, tested, stable. categorize() (list mode), extract_keywords(), extract_entities(), is_question(), text_to_question(), merge_questions(), rewrite(), subject_to_question(), summarize(), run_custom() Yes - ready for reliable use.
🧪 Experimental Added to the package but not fully evaluated. Functional, but quality may vary. categorize() (tree mode), translate(), propositionize(), check_fact() Use with caution - outputs not yet validated.

⚙️ 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.

  • logprobs: bool → Returns token-level probabilities for the generated output. You can also specify top_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.

  • user_prompt: str → Allows you to inject a custom instruction or 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 from 0.0 to 2.0.

  • validator: Callable (Experimental) → Forces TheTool to validate the output result based on your custom validator. Validator should return a boolean. If the validator fails, TheTool will retry to get another output by modifying temperature. You can also specify max_validation_retries=<N>.

  • priority: int (Experimental) → Task execution priority level. Affects processing order in queues. Note: This feature works if it's supported by the model and vLLM.


🧩 ToolOutput

Every tool of TextTools returns a ToolOutput object which is a BaseModel with attributes:

  • result: Any
  • analysis: str
  • logprobs: list
  • errors: list[str]
  • ToolOutputMetadata
    • tool_name: str
    • processed_at: datetime
    • execution_time: float

Note: You can use repr(ToolOutput) to print your output with all the details.


🧨 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

client = OpenAI(base_url = "your_url", API_KEY = "your_api_key")
model = "model_name"

the_tool = TheTool(client=client, model=model)

detection = the_tool.is_question("Is this project open source?")
print(repr(detection))

⚡ Quick Start (Async)

import asyncio
from openai import AsyncOpenAI
from texttools import AsyncTheTool

async def main():
    async_client = AsyncOpenAI(base_url="your_url", api_key="your_api_key")
    model = "model_name"

    async_the_tool = AsyncTheTool(client=async_client, model=model)
    
    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(repr(translation))
    print(repr(keywords))

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 Runner)

from pydantic import BaseModel
from texttools import BatchRunner, BatchConfig

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"
)

class Output(BaseModel):
    entities: list[str]

runner = BatchRunner(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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hamtaa_texttools-1.2.0.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hamtaa_texttools-1.2.0-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file hamtaa_texttools-1.2.0.tar.gz.

File metadata

  • Download URL: hamtaa_texttools-1.2.0.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for hamtaa_texttools-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2c17e88cc7238a51f356dec275939206cb22f86c6d4ae42552729e2a7172d7d1
MD5 411f3c4f015f7144b566ed18f658609b
BLAKE2b-256 67d75af9705bc2fd9858d5fc610b7965f752187dda8c4720864000d72fdf5703

See more details on using hashes here.

File details

Details for the file hamtaa_texttools-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hamtaa_texttools-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12742819b081b795a565ea4927700b4a16e814609c04506e29a5fc4690b65d1e
MD5 273664073d73f6272e18aaea41aa8530
BLAKE2b-256 4778250fba40d320a412e0cfd611dfb75edaf1bd3e6c4b45c1ce1b55a8be8881

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