Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pysubstringsearch

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pysubstringsearch

A Python library written in Rust that searches for substrings quickly using a Suffix Array

  • 0.7.1
  • PyPI
  • Socket score

Maintainers
1

Logo

A Python library written in Rust that searches for substrings quickly using a Suffix Array

license Python Build PyPi

Table of Contents

About The Project

PySubstringSearch is a library designed to search over an index file for substring patterns. In order to achieve speed and efficiency, the library is written in Rust. For string indexing, the library uses libsais suffix array construction library. The index created consists of the original text and a 32bit suffix array struct. To get around the limitations of the Suffix Array Construction implementation, the library uses a proprietary container protocol to hold the original text and index in chunks of 512MB.

The module implements a method for searching.

  • search - Find different entries with the same substring concurrently. Concurrency increases as the index file grows in size with multiple inner chunks.
  • search_multiple - same as search but accepts multiple substrings in a single call

Built With

Performance

500MB File
LibraryFunctionTime#ResultsImprovement Factor
ripgrepyRipgrepy('google', '500mb').run().as_string.split('\n')47.2ms59431.0x
PySubstringSearchreader.search('google')497µs594395x
ripgrepyRipgrepy('text_two', '500mb').run().as_string.split('\n')44.7ms1591.0x
PySubstringSearchreader.search('text_two')14.9µs1593000x
7500MB File
LibraryFunctionTime#ResultsImprovement Factor
ripgrepyRipgrepy('google', '6000mb').run().as_string.split('\n')900ms628341.0x
PySubstringSearchreader.search('google')10.1ms6283489.1x
ripgrepyRipgrepy('text_two', '6000mb').run().as_string.split('\n')820ms01.0x
PySubstringSearchreader.search('text_two')200µs04100x

Installation

pip3 install PySubstringSearch

Usage

Create an index

import pysubstringsearch

# creating a new index file
# if a file with this name is already exists, it will be overwritten
writer = pysubstringsearch.Writer(
    index_file_path='output.idx',
)

# adding entries to the new index
writer.add_entry('some short string')
writer.add_entry('another but now a longer string')
writer.add_entry('more text to add')

# adding entries from file lines
writer.add_entries_from_file_lines('input_file.txt')

# making sure the data is dumped to the file
writer.finalize()

Search a substring within an index

import pysubstringsearch

# opening an index file for searching
reader = pysubstringsearch.Reader(
    index_file_path='output.idx',
)

# lookup for a substring
reader.search('short')
>>> ['some short string']

# lookup for a substring
reader.search('string')
>>> ['some short string', 'another but now a longer string']

# lookup for multiple substrings
reader.search_multiple(
    [
        'short',
        'longer',
    ],
)
>>> ['some short string', 'another but now a longer string']

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Gal Ben David - gal@intsights.com

Project Link: https://github.com/Intsights/PySubstringSearch

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc