I Built a Search Engine With Zero Dependencies — Just Python 3.14's Standard Library
Описание и применение
SwiftSearch показывает, что полнотекстовый поиск можно реализовать без сторонних библиотек, используя только стандартную библиотеку Python 3.14.
Задача
Modern web apps often add heavy search stacks (Elasticsearch, Whoosh, FastAPI, etc.) that inflate dependencies, runtime, and complexity for simple local search needs.
Результат
SwiftSearch demonstrates that a lightweight, dependency‑free search engine can be built with only Python’s standard library, achieving sub‑millisecond query times and eliminating external services.
Рабочий процесс
- 1. Build an inverted index in memory with
collections.defaultdictanddataclassesto store postings and document frequencies. - 2. Tokenize text using
unicodedata.normalize('NFC')and a simple alphanumeric split. - 3. Serve HTTP requests with
http.server, handling dual routing (API and static assets) by inspectingself.pathand setting headers manually. - 4. Return JSON search results and render a demo page for the command‑palette UI.
- 5. Verify zero external imports with a grep check across the codebase.
- 6. Run the server with
python -m swiftsearch serveand perform queries like/search?q=python.
Доказательства
SwiftSearch runs with a single command (python -m swiftsearch serve), using only stdlib modules: collections.defaultdict for inverted indexing, unicodedata for tokenization, http.server for the API, and a simple linear scoring formula.
Every import resolved to a Python 3.14 built‑in: argparse, collections, dataclasses, html, http.server, json, pathlib, time, unicodedata, urllib.parse.
- Дата записи: 2026-09-11T04:01:14.660Z