Skip to main content

A high-performance text pattern matching library built with Rust

Project description

Voluta

A high-performance Python library for searching text patterns using the Aho-Corasick algorithm. Built with Rust for blazing fast processing.

Features

  • Memory-mapped file processing for optimal performance with large files
  • Parallel processing option for multi-core utilization
  • Configurable chunk sizes for memory management and performance tuning
  • Direct byte matching for maximum control and performance
  • Returns full match information (start and end positions)
  • Case insensitive matching
  • Support for overlapping pattern matches

Installation

Prerequisites

  • Rust (latest stable)
  • Python 3.13
  • uv
  • just

Building from source

# Clone repository
git clone https://github.com/trustshield/voluta.git && cd voluta

# Setup environment
uv venv
source .venv/bin/activate
uv sync --dev

# Build
just build

# Test
just test

Installing the wheel

After building, you can install the wheel in another project:

# The wheel file will be in target/wheels/
pip install /path/to/voluta/target/wheels/voluta-*.whl

# Alternatively, install directly from GitHub
pip install git+https://github.com/trustshield/voluta.git

Usage

Basic usage

import voluta

# Create a TextMatcher with patterns to search for
# Case insensitivity and overlapping matching are enabled by default
matcher = voluta.TextMatcher(["error", "warning", "critical"])

# Match patterns in a file (line-by-line)
# Returns (line_num, start_pos, end_pos, pattern)
matches = matcher.match_file("path/to/large.log")
for line_num, start, end, pattern in matches:
    print(f"Found '{pattern}' on line {line_num}, positions {start}-{end}")

# Using memory-mapped matching (faster for large files)
# Returns (byte_offset, end_offset, pattern)
matches = matcher.match_file_memmap("path/to/large.log", None)  # use default chunk size
for start, end, pattern in matches:
    print(f"Found '{pattern}' at byte positions {start}-{end}")

# Using parallel memory-mapped matching (maximum performance)
matches = matcher.match_file_memmap_parallel("path/to/large.log", None, None)

Advanced usage

# Specify chunk size (in bytes)
chunk_size = 8 * 1024 * 1024  # 8MB
matches = matcher.match_file_memmap("path/to/large.log", chunk_size)

# Specify chunk size and number of threads
chunk_size = 4 * 1024 * 1024  # 4MB
n_threads = 8
matches = matcher.match_file_memmap_parallel("path/to/large.log", chunk_size, n_threads)

# Direct byte matching for maximum performance
with open("path/to/large.log", "rb") as f:
    content = f.read()  # Or load bytes from any source
    matches = matcher.match_bytes(content)
    for start, end, pattern in matches:
        print(f"Found '{pattern}' at positions {start}-{end}")

# Simple example of finding specific text patterns
text = "The fox jumped over the fence. The fox is quick."
matcher = voluta.TextMatcher(["fox", "jump", "quick"])
matches = matcher.match_bytes(text.encode())
for start, end, pattern in matches:
    context = text[max(0, start-5):min(len(text), end+5)]
    print(f"Found '{pattern}' at {start}-{end}: '...{context}...'")

# Finding overlapping patterns
text = "abcdefgh"
# Overlapping matches are enabled by default to find all possible matches
matcher = voluta.TextMatcher(["abcd", "bcde", "cdef"])
matches = matcher.match_bytes(text.encode())
for start, end, pattern in matches:
    print(f"Found '{pattern}' at {start}-{end}")
    
# Disable overlapping matches if needed
matcher = voluta.TextMatcher(["abcd", "bcde", "cdef"], overlapping=False)

# Case sensitivity control
text = "Hello WORLD"
# By default, case insensitivity is enabled
matcher = voluta.TextMatcher(["hello", "world"])  # Will match both Hello and WORLD
# Disable case insensitivity if needed
matcher = voluta.TextMatcher(["hello", "world"], case_insensitive=False)  # Will only match exact case

Performance

The memory-mapped approach is significantly faster than line-by-line processing, especially for large files. For optimal performance:

  • Use match_file_memmap_parallel for multi-core systems
  • For maximum control and performance, use match_bytes with pre-loaded content
  • Test different chunk sizes for your specific hardware (typically 4-16MB works well)
  • For files under 100MB, the performance difference may be less noticeable
  • Note that enabling overlapping matches may impact performance

Thanks

This library is a wrapper of BurntSushi/aho-corasick.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

voluta-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl (500.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

voluta-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl (463.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.whl (451.1 kB view details)

Uploaded CPython 3.13macOS 10.14+ x86-64

voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.macosx_11_0_arm64.macosx_10_14_universal2.whl (856.9 kB view details)

Uploaded CPython 3.13macOS 10.14+ universal2 (ARM64, x86-64)macOS 10.14+ x86-64macOS 11.0+ ARM64

File details

Details for the file voluta-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for voluta-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4e577e38b7a1e14ea1faa8d9f3ab097c113da6a0d8729b4bc362421425500441
MD5 09d742c5905db4bcfc8f7442237d8f78
BLAKE2b-256 ad99c92b4a5154e269c3cd0c97aee0090635b09f1d5539acd722116da8d328ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for voluta-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: publish-to-pypi.yml on trustshield/voluta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file voluta-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for voluta-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 22cd59f4734fff742c0e9f7f56e4281c7135e7aad1a0340d58a26406c3067043
MD5 3351108fd47a6e6c3ffbbdb428294ac9
BLAKE2b-256 b53d3795f85693ad7bf53d9e31a02ec039e7ac8a7ad981d9d84c768fbc1c468c

See more details on using hashes here.

Provenance

The following attestation bundles were made for voluta-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: publish-to-pypi.yml on trustshield/voluta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 bd107854f5f04dc0cbf961ad68d5664b098c4a089ff29e4bd70ff0e37269ba5b
MD5 c9a166e05b633d2ce349d6040203678d
BLAKE2b-256 433abe2c7395320ca56268003a88cf6213fdba26448a9e0de52d5a0d01f52f78

See more details on using hashes here.

Provenance

The following attestation bundles were made for voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.whl:

Publisher: publish-to-pypi.yml on trustshield/voluta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.macosx_11_0_arm64.macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.macosx_11_0_arm64.macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 912770aa6c48817a3f82ef887338cae363c7699798d10b4f96492d7ef0290cef
MD5 8ca242668a60028fd3a79dbcd6e677bc
BLAKE2b-256 6238eb5143563be33f0d3a6ac603569af0e2176a559e5a43268e53c4fecb2d1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for voluta-0.1.0-cp313-cp313-macosx_10_14_x86_64.macosx_11_0_arm64.macosx_10_14_universal2.whl:

Publisher: publish-to-pypi.yml on trustshield/voluta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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