PyFTS5


NamePyFTS5 JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA lightweight wrapper for in‑memory SQLite FTS5 full‑text search in Python.
upload_time2025-02-14 21:45:08
maintainerNone
docs_urlNone
authorRaúl Speroni
requires_python<4.0,>=3.8
licenseMIT
keywords sqlite fts5 full-text search python sqlite3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
poetry install
```

If published on PyPI, install via pip:

```bash 
pip install PyFTS5
```

## Usage
Below is a quick example:

```python
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:

```bash
poetry run pytest
```

## License
This project is licensed under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "PyFTS5",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "sqlite, fts5, full-text search, python, sqlite3",
    "author": "Ra\u00fal Speroni",
    "author_email": "raulsperoni@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/31/d5/40fb3a04d0c4772e069bf56a1168cbf8b40333f65eee5df1086bff4bdc90/pyfts5-0.1.0.tar.gz",
    "platform": null,
    "description": "# PyFTS5\n\n**PyFTS5** is a lightweight Python library that wraps an in\u2011memory SQLite database with FTS5 full\u2011text search capabilities. It provides a simple, Pythonic API to add documents (with optional IDs) and perform various full\u2011text searches using common operators. The library also leverages SQLite\u2019s built\u2011in highlighting function to mark matched terms.\n\n## Features\n\n- **In\u2011Memory Database:** Uses an in\u2011memory SQLite database for fast, lightweight searches.\n- **FTS5 Integration:** Leverages SQLite\u2019s C\u2011implemented FTS5 extension for efficient full\u2011text indexing and search.\n- **Document IDs:** Allows you to insert documents with specific IDs, so that search results carry a persistent identifier.\n- **Helper Search Methods:** Supports common queries:\n  - **Generic search:** Direct MATCH queries.\n  - **Phrase search:** Exact phrase matching.\n  - **Prefix search:** Match tokens beginning with a given prefix.\n  - **Boolean operators:** AND, OR, NOT combinations.\n  - **NEAR search:** Find terms within a specified distance.\n- **Highlighting:** Optionally return search results with matched tokens highlighted (using SQLite\u2019s `highlight()` function).\n- **Context Manager:** Implements `__enter__` and `__exit__` so that the connection is automatically closed when finished.\n\n## Installation\n\n### Via Poetry\n\nClone the repository and run:\n\n```bash\npoetry install\n```\n\nIf published on PyPI, install via pip:\n\n```bash \npip install PyFTS5\n```\n\n## Usage\nBelow is a quick example:\n\n```python\nfrom fts_search_db import FullTextSearchDB\n\n# Prepare some documents as (doc_id, content) pairs.\ndocs = [\n    (101, \"The quick brown fox jumps over the lazy dog\"),\n    (102, \"Never jump over the lazy dog quickly\"),\n    (103, \"A quick movement of the enemy will jeopardize six gunboats\"),\n    (104, \"Quick thinking leads to quick decisions\"),\n]\n\n# Use the class as a context manager for automatic cleanup.\nwith FullTextSearchDB(docs) as fts_db:\n    # Perform a generic search (without highlighting).\n    results = fts_db.search(\"quick AND dog\")\n    for doc_id, content in results:\n        print(f\"Doc {doc_id}: {content}\")\n\n    # Perform a search with highlighting enabled.\n    highlighted = fts_db.search(\"quick AND dog\", highlight=True, hl_prefix=\"<<\", hl_suffix=\">>\")\n    for doc_id, hl_text, content in highlighted:\n        print(f\"Doc {doc_id} (highlighted): {hl_text}\")\n```\n\n## Testing\nUnit tests are written with pytest. To run the tests, simply run:\n\n```bash\npoetry run pytest\n```\n\n## License\nThis project is licensed under the MIT License.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight wrapper for in\u2011memory SQLite FTS5 full\u2011text search in Python.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/raulsperoni/PyFTS5/blob/main/README.md",
        "Homepage": "https://github.com/raulsperoni/PyFTS5",
        "Repository": "https://github.com/raulsperoni/PyFTS5"
    },
    "split_keywords": [
        "sqlite",
        " fts5",
        " full-text search",
        " python",
        " sqlite3"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1f208b0b87ccc269adc86345e1f34e234b92214776a84a525ccfd32310ca4aa2",
                "md5": "eb0eecaf3893523a0d8b14f903916d3b",
                "sha256": "d946f747a1c7b0cd517edcae12d4f22ac9cc273458be41a0bd9fa7947017dec0"
            },
            "downloads": -1,
            "filename": "pyfts5-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb0eecaf3893523a0d8b14f903916d3b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 5004,
            "upload_time": "2025-02-14T21:45:04",
            "upload_time_iso_8601": "2025-02-14T21:45:04.818335Z",
            "url": "https://files.pythonhosted.org/packages/1f/20/8b0b87ccc269adc86345e1f34e234b92214776a84a525ccfd32310ca4aa2/pyfts5-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "31d540fb3a04d0c4772e069bf56a1168cbf8b40333f65eee5df1086bff4bdc90",
                "md5": "acafefacf5656bf8554c0d56ce83896a",
                "sha256": "545a566c948391f663113642b73ac08b642313c959772eb5c7100d2781086fc6"
            },
            "downloads": -1,
            "filename": "pyfts5-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "acafefacf5656bf8554c0d56ce83896a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4098,
            "upload_time": "2025-02-14T21:45:08",
            "upload_time_iso_8601": "2025-02-14T21:45:08.010630Z",
            "url": "https://files.pythonhosted.org/packages/31/d5/40fb3a04d0c4772e069bf56a1168cbf8b40333f65eee5df1086bff4bdc90/pyfts5-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-14 21:45:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "raulsperoni",
    "github_project": "PyFTS5",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyfts5"
}
        
Elapsed time: 1.48051s