Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A Python library written in Rust that searches for substrings quickly using a Suffix Array
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 callLibrary | Function | Time | #Results | Improvement Factor |
---|---|---|---|---|
ripgrepy | Ripgrepy('google', '500mb').run().as_string.split('\n') | 47.2ms | 5943 | 1.0x |
PySubstringSearch | reader.search('google') | 497µs | 5943 | 95x |
ripgrepy | Ripgrepy('text_two', '500mb').run().as_string.split('\n') | 44.7ms | 159 | 1.0x |
PySubstringSearch | reader.search('text_two') | 14.9µs | 159 | 3000x |
Library | Function | Time | #Results | Improvement Factor |
---|---|---|---|---|
ripgrepy | Ripgrepy('google', '6000mb').run().as_string.split('\n') | 900ms | 62834 | 1.0x |
PySubstringSearch | reader.search('google') | 10.1ms | 62834 | 89.1x |
ripgrepy | Ripgrepy('text_two', '6000mb').run().as_string.split('\n') | 820ms | 0 | 1.0x |
PySubstringSearch | reader.search('text_two') | 200µs | 0 | 4100x |
pip3 install PySubstringSearch
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']
Distributed under the MIT License. See LICENSE
for more information.
Gal Ben David - gal@intsights.com
Project Link: https://github.com/Intsights/PySubstringSearch
FAQs
A Python library written in Rust that searches for substrings quickly using a Suffix Array
We found that pysubstringsearch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.