Skip to main content

A high-level NLP toolkit built on top of modern LLMs.

Project description

TextTools

PyPI License

📌 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, categorization, NER extraction, and more - designed to help you integrate AI-powered text processing into your applications with minimal effort.


✨ Features

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

  • categorize() - Classify text into given categories
  • extract_keywords() - Extract keywords from the text
  • extract_entities() - Perform Named Entity Recognition (NER)
  • is_question() - Detect if the input is phrased as a question
  • to_question() - Generate questions from the given text / subject
  • merge_questions() - Merge multiple questions into one
  • augment() - Rewrite text in different augmentations
  • summarize() - Summarize the given text
  • translate() - Translate text between languages
  • propositionize() - Convert a text into atomic, independent, meaningful sentences
  • is_fact() - Check whether a statement is a fact based on the source text
  • run_custom() - Custom tool that can do almost anything

🚀 Installation

Install the latest release via PyPI:

pip install -U hamtaa-texttools

📊 Tool Quality Tiers

Status Meaning Tools Safe for Production?
✅ Production Evaluated and tested. categorize() (list mode), extract_keywords(), extract_entities(), is_question(), to_question(), merge_questions(), augment(), summarize(), run_custom() Yes - ready for reliable use.
🧪 Experimental Added to the package but not fully evaluated. categorize() (tree mode), translate(), propositionize(), is_fact() Use with caution

⚙️ Additional Parameters

  • 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 into the model alongside the main template.

  • temperature: float → Determines how creative the model should respond. Takes a float number between 0.0 and 2.0.

  • validator: Callable (Experimental) → Forces the tool to validate the output result based on your validator function. 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) → Affects processing order in queues.
    Note: This feature works if it's supported by the model and vLLM.

  • timeout: float → Maximum time in seconds to wait for the response before raising a timeout error.
    Note: This feature is only available in AsyncTheTool.


🧩 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
  • Serialize output to JSON using the to_json() method.

  • Verify operation success with the is_successful() method.

  • Convert output to a dictionary with the to_dict() method.


🧨 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(detection.to_json())

⚡ 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_lang="English")
    keywords_task = async_the_tool.extract_keywords("This open source project is great for processing large datasets!")

    (translation, keywords) = await asyncio.gather(translation_task, keywords_task)
    
    print(translation.to_json())
    print(keywords.to_json())

asyncio.run(main())

✅ Use Cases

Use TextTools when you need to:

  • 🔍 Classify large datasets quickly without model training
  • 🧩 Integrate LLMs into production pipelines (structured outputs)
  • 📊 Analyze large text collections using embeddings and categorization

🤝 Contributing

Contributions are welcome!
Feel free to open issues, suggest new features, or submit pull requests.

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-2.0.0.tar.gz (23.8 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-2.0.0-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hamtaa_texttools-2.0.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hamtaa_texttools-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fd867bd1120555592af479e4d887aac7c1730a7e32248fac2c0b45162c9d21fb
MD5 e4be9ac9d9c33e3a8d48eeefb550c892
BLAKE2b-256 8803c026cbfddd5f6ff5cb834e72d09ff4f39c55cf736de33e9626e6b6af09b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hamtaa_texttools-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 31.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hamtaa_texttools-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e63d1ade195e9b12d628a96e0ba4e814de8dc9703e4b7923fb0fb66da3f19455
MD5 2b69fae5b5f7c1454b0f87567b4f599c
BLAKE2b-256 e13fd149bfc5a63d1e0d4f2a4bd299a1705239550fec66d07bd7a96b866c458b

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