pocketsearch
A pure-Python full-text indexing search library based on SQLite and the FTS5 extension, supporting both on-disk and in-memory search indexes.
- A simple API (inspired by the ORM layer of the Django web framework) for defining schemas and searching - no need to write SQL
- Multi-field indices using schemas including text, numeric and date/datetime search
- Prefix, phrase and initial token queries
- Spell checking
- Boolean search queries
- Highlightning search results and extracting snippets
- Autocomplete features
Pocketsearch does not have any dependencies other than Python (3.8 or higher) itself.
Quick start
Install using PIP:
pip install pocketsearch
Create a search index using a PocketWriter and store it to database my_db.db:
import pocketsearch
with pocketsearch.PocketWriter(db_name="my_db.db") as pocket_writer:
pocket_writer.insert(text="Hello world")
Open the search index using a PocketReader to perform searches:
import pocketsearch
with pocketsearch.PocketReader(db_name="my_db.db") as pocket_reader:
for result in pocket_reader.search(text="Hello world"):
print(result.text)
You can define custom schemas to create multi-field indices:
import pocketsearch as ps
class Product(ps.Schema):
price = ps.Int()
description = ps.Text(index=True) # part of full text (FT) index
category = ps.Text() # not part of FT index
with ps.PocketWriter(db_name="my_db.db",schema=Product) as pocket_writer:
pocket_writer.insert(description="Apple",category="Fruit",price=3.21)
pocket_writer.insert(description="Orange",category="Fruit",price=4.11)
with ps.PocketReader(db_name="my_db.db",schema=Product) as pocket_reader:
# Search for products with a price greater than or equal 3:
print(pocket_reader.search(price__gte=3).count())
Read the complete documentation at https://pocketsearch.readthedocs.io/
In-memory search index
Use QuickPocket to run the whole search index in-memory:
import pocketsearch
with pocketsearch.QuickPocket() as index:
index.insert(text="Hello world !")
print(index.search(text="world").count())
Once the context manager is closed, the database will disappear too.
You can use the PocketSearch class directly if you prefer:
import pocketsearch
index = pocketsearch.PocketSearch()
index.insert(text="Hello world !")
print(index.search(text="world").count())
Use cases
pocketsearch is intended for projects looking for a server-less, seamless integration into existing Python projects with low to medium-sized document collections.
Please refer to https://github.com/kaykay-dv/pocketsearch/tree/main/tests/DCEP to see how pocketsearch can be used to index more than 160,000 documents.
Metadata
Release files for pocketsearch 0.42.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pocketsearch-0.42.0.tar.gz | 37.6 kB | Without provenance | Details for pocketsearch-0.42.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pocketsearch-0.42.0-py3-none-any.whl | Python 3 | none | any | Details for pocketsearch-0.42.0-py3-none-any.whl |
Total release size: 77.5 kB
Release files / pocketsearch-0.42.0.tar.gz
| Download URL | pocketsearch-0.42.0.tar.gz |
|---|---|
| Size | 37.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
829e96c62c99a7f497a8df58e69b7eb0524f08d6a4139b931b25420668486368
|
|
BLAKE2b-256 checksum How to use checksums |
facfd4c60b1f16b3877481a4941339d6c339e658da6636e536f8b98f683d8981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / pocketsearch-0.42.0-py3-none-any.whl
| Download URL | pocketsearch-0.42.0-py3-none-any.whl |
|---|---|
| Size | 39.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e80ee36ae349c2321081c24d7f11a524ca2a81ffeec84df667ff7074275d02c6
|
|
BLAKE2b-256 checksum How to use checksums |
af32603dc3d6033d66f54b18b6389e85e3b473e4e3e342419013142f051ef661
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for pocketsearch 0.42.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.