Skip to main content

High-speed keyword search with shared memory — Python binding for iWord

Project description

iword — High-speed keyword search with shared memory

Python binding for iWord: zero-copy keyword search via System V shared memory.

Requirements

  1. Build the shared library:

    git clone https://github.com/atfreaks/iword
    cd iword && make lib   # → bin/libiword.so
    
  2. Load a dictionary:

    bin/iwordctl load dict/spam_en.txt
    

Install

pip install iword

Usage

from iword import seek, map as iword_map, filter_text, extract_by_key
from iword import MODE_HTML, MODE_FORBID, KEY_SPAM

# Search for a single word
key = seek("spam")           # returns 2 (KEY_SPAM), or -1 if not found

# Scan text for all matches
matches = iword_map("Get your free prize now!", MODE_HTML | MODE_FORBID)
# [Match(position=8, length=4, key=2), ...]

# Replace matches with '*'
clean = filter_text("buy spam now", MODE_HTML | MODE_FORBID)
# "buy **** now"

# Extract matches by category
spam_only = extract_by_key(text, KEY_SPAM, MODE_HTML | MODE_FORBID)

LangChain Integration

from langchain.tools import BaseTool
from iword import map as iword_map, MODE_HTML, MODE_FORBID, KEY_SPAM

class IWordSpamFilter(BaseTool):
    name = "iword_spam_filter"
    description = "Detect spam keywords in text using shared memory dictionary."

    def _run(self, text: str) -> dict:
        matches = iword_map(text, MODE_HTML | MODE_FORBID)
        spam = [m for m in matches if m.key == KEY_SPAM]
        return {"is_spam": len(spam) > 0, "matches": len(spam)}

Notes

  • Requires bin/libiword.so (built via make lib) at runtime
  • Dictionary must be loaded via iwordctl load before calling seek/map
  • System V SHM is not available on AWS Lambda, Cloud Run, or other serverless platforms

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

iword-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

iword-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file iword-0.1.0.tar.gz.

File metadata

  • Download URL: iword-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for iword-0.1.0.tar.gz
Algorithm Hash digest
SHA256 44c8038d1db41632fb5585a00d118df9f7d347989f1bca3108d3c5c7343089ba
MD5 73fdaac12fc86e10b17f517d01234c9a
BLAKE2b-256 dbe6870b38757b21bb46b107b6a1f2462c1b0f6cbff9e3fc6d3442266d81f05b

See more details on using hashes here.

File details

Details for the file iword-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iword-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for iword-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 881ab70a5a3a7c20f8222f9bb0dcefa0f7d4c1cb7357c640f37c6a170088b282
MD5 7da4aa0edb0b2b5df4dbdc6571a85dd1
BLAKE2b-256 cbdee203cca7171548dc23bafd6c772c15c72353f0455f17a562fbbd0a81c0b3

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