Whoosh-NG
Whoosh-NG is a modern, pure-Python full-text indexing and search library. Version 4.2.0 brings a complete modernization with Python 3.11+ support, strict type annotations, optional feature profiles, and automated semantic releases.
Quick Start
- Full-text search - BM25/BM25F scoring with phrase queries
- Fielded documents - Structured indexing with typed fields
- Query parsing - Flexible parser with boosting and syntax options
- Facets & sorting - Group and sort results by any field
- Highlighting - Snippet extraction with customizable formatters
- Spell checking - Built-in spelling correction
- Event-driven architecture - Plugin system with hooks and middleware
- Optional extensions - Vector search, async, FastAPI, metrics, and more
Installation
Core Installation
pip install whoosh-ng
Optional Profiles
# Vector search with NumPy
pip install "whoosh-ng[vector]"
# Async wrappers
pip install "whoosh-ng[async]"
# FastAPI REST API integration
pip install "whoosh-ng[api]"
# Prometheus metrics
pip install "whoosh-ng[metrics]"
# PostgreSQL backend
pip install "whoosh-ng[postgres]"
# Fuzzy matching
pip install "whoosh-ng[fuzzy]"
# Phonetic search
pip install "whoosh-ng[phonetic]"
# Profiling tools (psutil, re2, pystemmer)
pip install "whoosh-ng[profiling]"
# Fast stemming with PyStemmer C backend
pip install "whoosh-ng[fast-stemming]"
# All optional features
pip install "whoosh-ng[vector,async,api,metrics,postgres,fuzzy,phonetic,profiling,fast-stemming]"
Development Installation
pip install "whoosh-ng[dev]"
Documentation
- API Reference - Complete module documentation
- User Guides - Tutorials and best practices
- Examples - Runnable code examples
- Data Sources - SQL, REST, GraphQL, CSV, JSON, Parquet data sources
- French Documentation - Documentation en français
- LLM-Friendly Docs:
llms.txt(index) |llms-full.txt(complete API)
Recent Changes in 4.2.0
Performance Highlights
| Gain | Scope | Notes |
|---|---|---|
| +68% indexing speed | 20k docs | analyzing phase reduced from 8.6s to 2.7s |
| +35% token creation | per-document | Token migrated to __slots__ |
| -93% write_block calls | 20k docs | Field cache inline in W3PostingsWriter |
| Compact postings | all segments | Single-posting and short-inline fast paths |
| Global compiled regex | RegexTokenizer |
Default pattern compiled once at module load |
| Stemmer provider | StemmingAnalyzer |
Select auto/internal/pystemmer backends |
Added
- Plugin System (
whoosh.plugins):Pluginbase class andPluginManagerwith entry-point auto-discovery, version validation, conflict detection, enable/disable, and dependency management - Registry System (
whoosh.registry): Generic registry plusStorageRegistry,AnalyzerRegistry,RankingRegistry,SuggestRegistry,VectorRegistry,AutocompleteRegistry, andBackendRegistry - Middleware Pipeline (
whoosh.middleware):Middlewarebase class (sync + async),MiddlewareContext,MiddlewareChain,MiddlewareRegistry, with officialMetricsMiddleware,CacheMiddleware,CompressionMiddleware,EncryptionMiddleware, andPrometheusMiddleware - Event Bus (
whoosh.event_bus):EventBuswith subscribe/publish/clear - Hook System (
whoosh.hooks):hookimpl,register_hook,call_hook - Backends:
BackendABC with lifecycle hooks,FileBackend, andSQLiteBackend - Provider Architecture:
VectorProvider/VectorField,NumpyProviderfor vector similarity search - Autocomplete Plugin (
whoosh_modern.autocomplete): Inverted index and edge-ngram autocomplete - FastAPI Plugin (
whoosh_fastapi): REST endpoints for search, autocomplete, vector search, and health checks - Admin UI Plugin (
whoosh_admin): Dashboard for index administration - Entry Points: Auto-loaded plugins under
whoosh.pluginsgroup - Data Sources (
whoosh_modern.data_sources):DataSourceprotocol withObservableDataSource,SQLSource(connection pooling, GROUP BY/JOIN/incremental sync),SQLAlchemySource,RESTSource(page/offset/cursor pagination + auth),GraphQLSource,FastCSVSource,JSONSource,ParquetSource,PandasSource,PolarsSource,PeeweeSource,TortoiseSource,PydanticSource, andDataSourceConfigfor declarative config from dict/JSON/YAML files - Schema Discovery (
whoosh_modern.schema_discovery): Result-set introspection with duplicate column detection and JSON/JSONB handling - FacetManager (
whoosh_modern.facets): Auto-discovery of facetable fields with manual override support - Validation Framework (
whoosh_modern.validation): 4-level validation (STRICT/WARN/SKIP/NONE) with typed exceptions and field context - Middleware Pipeline (
whoosh_modern.middleware):RetryMiddleware,LoggingMiddleware,CacheMiddlewarewith chainable pipeline - SearchView (
whoosh_modern.views): Unified interface integrating data sources, schema discovery, facets, validation, and middleware withbuild(),refresh(),reindex(),validate(),evolve_schema(), and strict mode - Stemmer Provider System (
whoosh_modern.analysis):get_stemmer(),register_stemmer(), auto-detection between internal Porter stemmer and PyStemmer C backend - Enhanced StemmingAnalyzer (
whoosh_modern.analysis): Acceptsstemmer="auto"|"internal"|"pystemmer"|providerparameter
Breaking Changes
Re-indexing required. The on-disk posting format in
W3TermInfoand position/char encoding inFormatshas changed. Indexes created with pre-2.0 versions are not readable by this release. Delete old index directories and re-create them.
Tokennow uses__slots__: code that iteratestoken.__dict__should usetoken.copy()or slot introspection insteadfinish_postings()signature changed:allow_compact=Truekeyword addedwhoosh_modernpackage structure changed: Import paths for data sources have been updated. For example,from whoosh_modern.data_sources import SQLSourceshould now befrom whoosh_modern.data_sources.sql import SQLSource. Please update your import statements accordingly.
Changed
- Distribution renamed from
whoosh-reloadedtowhoosh-ng(import namespace remainswhoosh) - Documentation links now absolute (GitHub Pages):
https://dorel14.github.io/whoosh-ng/en/... - Python 3.11+ required (dropped Python 3.9/3.10 support)
- Packaging cleaned: consolidated extras in
pyproject.toml - Type annotations modernized:
mypy src/whooshreports 0 errors,py.typedmarker included
Example: Simple Search
from whoosh import index
from whoosh.fields import Schema, TEXT, ID
from whoosh.qparser import QueryParser
# Define schema
schema = Schema(
id=ID(stored=True, unique=True),
title=TEXT(stored=True),
content=TEXT,
)
# Create index
ix = index.create_in("my_index", schema)
# Index documents
with ix.writer() as w:
w.add_document(id="1", title="Hello World", content="Welcome to Whoosh-NG")
w.add_document(id="2", title="Python Search", content="Fast text search library")
# Search
with ix.searcher() as s:
qp = QueryParser("content", ix.schema)
q = qp.parse("search library")
results = s.search(q)
for hit in results:
print(hit["title"], hit.score)
Example: FastAPI Integration
from fastapi import FastAPI
from whoosh import index
from whoosh.fields import Schema, TEXT, ID
from whoosh_fastapi import create_app
schema = Schema(id=ID(), title=TEXT(), content=TEXT())
ix = index.create_in("docs", schema)
# Create FastAPI app with Whoosh-NG endpoints
app = create_app(ix, prefix="/api/v1")
# Endpoints available:
# GET /api/v1/health - Health check
# POST /api/v1/search - Full-text search
# GET /api/v1/autocomplete?q= - Autocomplete suggestions
Example: Data Sources
SQLSource — Index from a SQL database
from whoosh_modern.data_sources.sql import SQLSource
from whoosh import index
from whoosh.fields import Schema, TEXT, NUMERIC
import sqlite3
conn = sqlite3.connect("mydb.db")
source = SQLSource(
connection=conn,
query="SELECT * FROM products",
incremental_field="updated_at",
id_field="id",
)
# Discover schema from actual result metadata
schema = source.discover_schema()
# Build index with SearchView
from whoosh_modern.views import SearchView
view = SearchView(name="products", source=source)
ix = view.build("indexdir")
RESTSource — Index from a REST API
from whoosh_modern.data_sources.rest import RESTSource
source = RESTSource(
url="https://api.example.com/v2/products",
pagination="page",
page_size=50,
headers={"Authorization": "Bearer your_token"},
)
schema = source.discover_schema()
docs = list(source.iter_documents())
SearchView — Full pipeline integration
from whoosh_modern.views import SearchView
from whoosh_modern.data_sources.sql import SQLSource
import sqlite3
conn = sqlite3.connect("mydb.db")
source = SQLSource(
connection=conn,
query="SELECT * FROM reuters_articles",
incremental_field="article_date",
id_field="id",
)
view = SearchView(name="reuters", source=source)
ix = view.build("indexdir")
# Incremental refresh
count = view.refresh()
# Full reindex
count = view.reindex()
Example: Vector Search
pip install "whoosh-ng[vector]" numpy
from whoosh import index
from whoosh.fields import Schema, TEXT, ID, VECTOR
from whoosh.vector import VectorField
from whoosh_modern.vector.plugin import VectorPlugin
from whoosh.plugins.manager import PluginManager
import numpy as np
# Create index with vector field
schema = Schema(
id=ID(stored=True),
title=TEXT(stored=True),
embedding=VECTOR(dim=384),
)
# Register vector plugin
VectorPlugin().register(PluginManager())
# Index with embeddings
ix = index.create_in("vector_db", schema)
with ix.writer() as w:
w.add_document(
id="doc1",
title="Python tutorial",
embedding=np.random.rand(384).astype(np.float32).tobytes()
)
Release files for whoosh-ng 4.2.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 | |
|---|---|---|---|
| whoosh_ng-4.2.0.tar.gz | 1.7 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| whoosh_ng-4.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.5 MB
Release files / whoosh_ng-4.2.0.tar.gz
| Download URL | whoosh_ng-4.2.0.tar.gz |
|---|---|
| Size | 1.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73c014fda5dfd5a8cb8d3138069b2f18a0f3aa9e03ecca224cebf99a1525b5f3
|
|
BLAKE2b-256 checksum How to use checksums |
80a25d39b43551d664660249ed678d78b7a9650687b84712b265d35ca5b9e56a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / whoosh_ng-4.2.0-py3-none-any.whl
| Download URL | whoosh_ng-4.2.0-py3-none-any.whl |
|---|---|
| Size | 795.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7d71953491735b8c1d62c6072ae5b06566aad96d72a80a11d5aadc4d8f56e84
|
|
BLAKE2b-256 checksum How to use checksums |
fd904bae22dff168980ed54b804216cb99fa69f67c2093d22f18d39aadf00240
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|