Skip to main content

Text Length Tool for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_tool_textlength


Swarmauri Tool · Text Length

A Swarmauri-ready helper that measures text length in characters, words, and sentences using NLTK tokenization. Drop it into content pipelines, moderation bots, or editorial agents to monitor message size and cadence.

  • Counts characters (excluding spaces) for quick size checks.
  • Uses NLTK tokenizers to calculate word and sentence totals accurately.
  • Returns a structured dictionary suitable for logging, analytics, or conversational outputs.

Requirements

  • Python 3.10 – 3.13.
  • nltk with the punkt_tab resource available (downloaded automatically on import).
  • Core Swarmauri dependencies (swarmauri_base, swarmauri_standard, pydantic).

Installation

Pick the packaging tool that fits your workflow; each command installs dependencies.

pip

pip install swarmauri_tool_textlength

Poetry

poetry add swarmauri_tool_textlength

uv

# Add to the current project and update uv.lock
uv add swarmauri_tool_textlength

# or install into the active environment without editing pyproject.toml
uv pip install swarmauri_tool_textlength

Tip: When building containers or offline environments, pre-fetch NLTK data with python -m nltk.downloader punkt_tab to avoid runtime downloads.

Quick Start

from swarmauri_tool_textlength import TextLengthTool

text = "This is a simple test sentence."

length_tool = TextLengthTool()
result = length_tool(text)

print(result)
# {
#   'num_characters': 26,
#   'num_words': 7,
#   'num_sentences': 1
# }

Usage Scenarios

Enforce Message Length in Moderation Bots

from swarmauri_tool_textlength import TextLengthTool

length_checker = TextLengthTool()
message = """Please keep replies under 50 words so the queue stays manageable."""

metrics = length_checker(message)
if metrics["num_words"] > 50:
    raise ValueError("Message too long for moderation queue")

Provide Real-Time Feedback in a Swarmauri Agent

from swarmauri_core.agent.Agent import Agent
from swarmauri_core.messages.HumanMessage import HumanMessage
from swarmauri_standard.tools.registry import ToolRegistry
from swarmauri_tool_textlength import TextLengthTool

registry = ToolRegistry()
registry.register(TextLengthTool())
agent = Agent(tool_registry=registry)

message = HumanMessage(content="Analyze how long this paragraph is compared to our guideline.")
response = agent.run(message)
print(response)

Batch Audit Documentation for Sentence Length

from pathlib import Path
from swarmauri_tool_textlength import TextLengthTool

length_tool = TextLengthTool()

for doc in Path("docs").rglob("*.md"):
    metrics = length_tool(doc.read_text(encoding="utf-8"))
    print(f"{doc}: {metrics['num_sentences']} sentences, {metrics['num_words']} words")

Scan an entire documentation set to identify sprawling sections or under-documented topics.

Troubleshooting

  • LookupError: Resource punkt_tab not found – Run python -m nltk.downloader punkt_tab ahead of time, especially in air-gapped deployments.
  • Unexpected character counts – The tool excludes spaces; adjust the implementation if you need raw length including whitespace.
  • Non-English text – NLTK’s default tokenizers target English. Swap in language-specific tokenizers if needed.

License

swarmauri_tool_textlength is released under the Apache 2.0 License. See LICENSE for full 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

swarmauri_tool_textlength-0.9.0.dev7.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file swarmauri_tool_textlength-0.9.0.dev7.tar.gz.

File metadata

  • Download URL: swarmauri_tool_textlength-0.9.0.dev7.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_tool_textlength-0.9.0.dev7.tar.gz
Algorithm Hash digest
SHA256 b4a6a95fe23c0c1d4d02bc467644b21212b697f3d781e56f356970721dfc52c2
MD5 d96a7e8fcd64ad7a115c355f52ea5083
BLAKE2b-256 1c39bdf68286126b4f9b9cb846618c818941e83bf0ddc5b83d9a7a5eee6c3f60

See more details on using hashes here.

File details

Details for the file swarmauri_tool_textlength-0.9.0.dev7-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_tool_textlength-0.9.0.dev7-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_tool_textlength-0.9.0.dev7-py3-none-any.whl
Algorithm Hash digest
SHA256 73ee8efdbb66510864b82b0754ac42a5900ef0918f1257c68b6e67d46bb32c58
MD5 ee8662b5e73738a0075d46517549d1d1
BLAKE2b-256 501b5d3a96fd21200adc0f60e42c6fb8c46caf99a6e51b65dea5d26689e4349c

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