Skip to main content

PyFTS5

PyFTS5 is a lightweight Python library that wraps an in‑memory SQLite database with FTS5 full‑text search capabilities. It provides a simple, Pythonic API to add documents (with optional IDs) and perform various full‑text searches using common operators. The library also leverages SQLite’s built‑in highlighting function to mark matched terms.

Features

  • In‑Memory Database: Uses an in‑memory SQLite database for fast, lightweight searches.
  • FTS5 Integration: Leverages SQLite’s C‑implemented FTS5 extension for efficient full‑text indexing and search.
  • Document IDs: Allows you to insert documents with specific IDs, so that search results carry a persistent identifier.
  • Helper Search Methods: Supports common queries:
    • Generic search: Direct MATCH queries.
    • Phrase search: Exact phrase matching.
    • Prefix search: Match tokens beginning with a given prefix.
    • Boolean operators: AND, OR, NOT combinations.
    • NEAR search: Find terms within a specified distance.
  • Highlighting: Optionally return search results with matched tokens highlighted (using SQLite’s highlight() function).
  • Context Manager: Implements __enter__ and __exit__ so that the connection is automatically closed when finished.

Installation

Via Poetry

Clone the repository and run:

poetry install

If published on PyPI, install via pip:

pip install PyFTS5

Usage

Below is a quick example:

from fts_search_db import FullTextSearchDB

# Prepare some documents as (doc_id, content) pairs.
docs = [
    (101, "The quick brown fox jumps over the lazy dog"),
    (102, "Never jump over the lazy dog quickly"),
    (103, "A quick movement of the enemy will jeopardize six gunboats"),
    (104, "Quick thinking leads to quick decisions"),
]

# Use the class as a context manager for automatic cleanup.
with FullTextSearchDB(docs) as fts_db:
    # Perform a generic search (without highlighting).
    results = fts_db.search("quick AND dog")
    for doc_id, content in results:
        print(f"Doc {doc_id}: {content}")

    # Perform a search with highlighting enabled.
    highlighted = fts_db.search("quick AND dog", highlight=True, hl_prefix="<<", hl_suffix=">>")
    for doc_id, hl_text, content in highlighted:
        print(f"Doc {doc_id} (highlighted): {hl_text}")

Testing

Unit tests are written with pytest. To run the tests, simply run:

poetry run pytest

License

This project is licensed under the MIT License.

Metadata

Release files for PyFTS5 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyFTS5 0.1.0
File Size Uploaded
pyfts5-0.1.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyFTS5 0.1.0
File Interpreter ABI Platform
pyfts5-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / pyfts5-0.1.0.tar.gz

Download URL pyfts5-0.1.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
545a566c948391f663113642b73ac08b642313c959772eb5c7100d2781086fc6
BLAKE2b-256 checksum
How to use checksums
31d540fb3a04d0c4772e069bf56a1168cbf8b40333f65eee5df1086bff4bdc90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2025.

Transparency log

Release files / pyfts5-0.1.0-py3-none-any.whl

Download URL pyfts5-0.1.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d946f747a1c7b0cd517edcae12d4f22ac9cc273458be41a0bd9fa7947017dec0
BLAKE2b-256 checksum
How to use checksums
1f208b0b87ccc269adc86345e1f34e234b92214776a84a525ccfd32310ca4aa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page