Skip to main content

A pure-Python full-text indexing search library based on SQLite and the FTS5 extension, supporting both on-disk and in-memory search indexes.

Project description

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.

Status

The package is actively maintained as of May 2025.

License: MIT Unit tests main Unit tests development Documentation Status

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

pocketsearch-0.41.0.tar.gz (34.6 kB view details)

Uploaded Source

Built Distribution

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

pocketsearch-0.41.0-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file pocketsearch-0.41.0.tar.gz.

File metadata

  • Download URL: pocketsearch-0.41.0.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pocketsearch-0.41.0.tar.gz
Algorithm Hash digest
SHA256 b578243a7999ab743d92e7160fa6e9336de8e9e4f0ceb9a18552907cfa7b52db
MD5 de6095db2b981da08e4d88a5b306b3c7
BLAKE2b-256 3c7e07bd0c09a5a64c8e77962490e87459c22120b4522ac5e8742f468a3cdf23

See more details on using hashes here.

File details

Details for the file pocketsearch-0.41.0-py3-none-any.whl.

File metadata

  • Download URL: pocketsearch-0.41.0-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pocketsearch-0.41.0-py3-none-any.whl
Algorithm Hash digest
SHA256 735e56fe19d3b152c78906e4a2bfd1a2fa0e54c07a31bdbf4d1197e91225b34c
MD5 b166df0188a507170d78f45ee1e46371
BLAKE2b-256 aa4c77fc545e913ae3275640ab40e1e3cf4a43fdab7185338c03004eef521d3c

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