Skip to main content

A tool for searching a specific word or phrase in a file.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_tool_searchword


Swarmauri Tool · Search Word

A Swarmauri utility for counting case-insensitive word or phrase occurrences in text files. The tool highlights matching lines and returns both the count and the decorated text so you can surface findings in agent conversations or CI logs.

  • Accepts any UTF-8 text file and performs case-insensitive matching.
  • Preserves surrounding context by returning the full line with ANSI highlighting (red) when a match is found.
  • Ships as a Swarmauri tool, so it can be registered alongside other agent capabilities.

Requirements

  • Python 3.10 – 3.13.
  • No external libraries beyond the core Swarmauri dependencies (swarmauri_base, swarmauri_standard, pydantic).

Installation

Choose the installer that matches your workflow; each command collects the required dependencies.

pip

pip install swarmauri_tool_searchword

Poetry

poetry add swarmauri_tool_searchword

uv

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

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

Tip: The tool reads files from disk, so ensure the executing process has permission to access the target path.

Quick Start

from swarmauri_tool_searchword import SearchWordTool

search = SearchWordTool()
result = search(file_path="docs/README.md", search_word="swarmauri")

print(result["count"])
# e.g., 5

for line in result["lines"]:
    print(line)

Matching lines are wrapped with ANSI escape codes (red foreground). When piping to logs or terminals that render ANSI, matches stand out immediately.

Usage Scenarios

Enforce Terminology in CI Pipelines

from pathlib import Path
from swarmauri_tool_searchword import SearchWordTool

search = SearchWordTool()

for file in Path("docs").rglob("*.md"):
    result = search(file_path=str(file), search_word="utilize")
    if result["count"] > 0:
        raise SystemExit(f"Forbidden term found in {file}: {result['count']} occurrences")

Stop merges when banned words or phrases appear in documentation.

Provide Explanations in an Agent Response

from swarmauri_core.agent.Agent import Agent
from swarmauri_core.messages.HumanMessage import HumanMessage
from swarmauri_standard.tools.registry import ToolRegistry
from swarmauri_tool_searchword import SearchWordTool

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

message = HumanMessage(content="How many times do we mention 'latency' in docs/overview.txt?")
response = agent.run(message)
print(response)

Agents can report both the count and the highlighted context back to the user.

Audit Configuration Files for Secrets

from swarmauri_tool_searchword import SearchWordTool

search = SearchWordTool()
config_files = [".env", "config/production.ini"]

for path in config_files:
    result = search(file_path=path, search_word="api_key")
    if result["count"]:
        print(f"Potential secret reference in {path}: {result['count']} matches")

Quickly scan multiple configuration files when performing security reviews.

Troubleshooting

  • FileNotFoundError – Confirm the path is correct and accessible. Relative paths are resolved from the current working directory of the process invoking the tool.
  • Invalid input – The tool only accepts string file paths and search terms. Validate arguments if they originate from user prompts.
  • ANSI escape codes in output – If your consumer cannot render ANSI, strip the escape sequences before displaying (e.g., with re.sub(r'\x1b\[[0-9;]*m', '', line)).

License

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

swarmauri_tool_searchword-0.3.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

swarmauri_tool_searchword-0.3.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_tool_searchword-0.3.0.tar.gz.

File metadata

  • Download URL: swarmauri_tool_searchword-0.3.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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_searchword-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6dc0ce5936bba4ccf42ebcf6696f597585392a626d3aa8ca05f6137133e30ac8
MD5 831c04f304a69b1f0df48b9213530cd0
BLAKE2b-256 ffa1205a802997f2b8167f880793afd3554c5b20bcf3c16389965868d5907600

See more details on using hashes here.

File details

Details for the file swarmauri_tool_searchword-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_tool_searchword-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","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_searchword-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7aa47c496fa241d124b264d29abbeee8898b79e400cf2828697711e42a1c3dc3
MD5 53351fb443189e924949558a77d3f821
BLAKE2b-256 6fbb73e24851c6f3bfe65a6d2e57cc57c53842eaf83d47c3d6f3ea0583863358

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