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 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 extractor, 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 built on top of LLMs.
Each tool is designed to work out-of-the-box with structured outputs (JSON / Pydantic).

  • categorize() - Classifies text into Islamic studies categories
  • is_question() - Binary detection of whether input is a question
  • extract_keywords() - Extracts keywords from text
  • extract_entities() - Named Entity Recognition (NER) system
  • summarize() - Text summarization
  • text_to_question() - Generates questions from text
  • merge_questions() - Merges multiple questions with different modes
  • rewrite() - Rewrites text with different wording/meaning
  • subject_to_question() - Generates questions about a specific subject
  • translate() - Text translation between languages
  • run_custom() - Allows users to define a custom tool with arbitrary BaseModel

⚙️ with_analysis, logprobs, output_lang, user_prompt and temperature parameters

TextTools provides several optional flags to customize LLM behavior:

  • with_analysis=True → Adds a reasoning step before generating the final output. Useful for debugging, improving prompts, or understanding model behavior.
    Note: This doubles token usage per call because it triggers an additional LLM request.

  • logprobs=True → 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.

  • output_lang="en" → 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="..." → 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=0.0 → Determines how creative the model should respond. Takes a float number from 0.0 to 1.0.

All these parameters can be used individually or together to tailor the behavior of any tool in TextTools.

Note: There might be some tools that don't support some of the parameters above.


🚀 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 \n --logprobs

# Example: Translation
translation = the_tool.translate("سلام، حالت چطوره؟" target_language="English", with_analysis=True)
print(translation.result)
print(translation.analysis)
# Output: "Hi! How are you?" \n --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
    the_tool = AsyncTheTool(client=async_client, model=model)

    # Example: Async Translation
    translation = await the_tool.translate("سلام، حالت چطوره؟", target_language="English")
    print(translation.result)
    # Output: "Hi! How are you?"

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
  • 👍 Automate common text-processing tasks without reinventing the wheel

🤝 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.1.1.tar.gz (22.5 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.1.1-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hamtaa_texttools-1.1.1.tar.gz
Algorithm Hash digest
SHA256 353d0a98d06f3de95858b8448222aed7acc27dc19a8a476bc733ac06984c1b98
MD5 9edc939da6adf704fbfd9c5e5b405d1f
BLAKE2b-256 105041b4926d0ada51637dafbd2b3d1e72b740ccce38f71677d9ac8cdcf764b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hamtaa_texttools-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27eca1626f4ebe84f82dbb02ecbd376bb4b1d4f193fa257c37add8f32a0017e9
MD5 645adc7796c2008cf4c70530e93d2537
BLAKE2b-256 3d21c2e1f7459c059bffdb06089632211c114c4c097eaf423e1b327ddfb40684

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