Skip to main content

Backends

Whoosh-NG supports pluggable storage backends through the Provider Architecture. The default backend stores data as files on disk, but you can use SQLite, PostgreSQL, S3, and more.

Built-in Backends​

BackendClassDescription
File (default)FileBackendStores index as files on disk
SQLiteSQLiteBackendStores index in SQLite database
MemoryMemoryBackendIn-memory backend (testing only)

File Backend (Default)​

from whoosh.index import create_in

# Uses FileBackend by default
ix = create_in("indexdir", schema)

Configuration​

from whoosh.backends.file import FileBackend

backend = FileBackend(
storage=FileStorage("indexdir"),
compound=True # Use compound files
)

SQLite Backend​

from whoosh.backends.sqlite import SQLiteBackend
from whoosh.store.sqlite import SQLiteStorage

storage = SQLiteStorage("index.db")
backend = SQLiteBackend(storage=storage)

Advantages​

  • Single file index
  • Better for transactional workloads
  • Easier backups
  • Supports concurrent reads

Disadvantages​

  • Slower for large indexes
  • Limited by SQLite performance

Memory Backend​

from whoosh.backends.memory import MemoryBackend

backend = MemoryBackend()
# Useful for testing

Custom Backend​

Create a custom backend by subclassing Backend:

from whoosh.backends.abc import Backend

class MyBackend(Backend):
def create(self):
"""Create a new segment."""
pass

def open(self):
"""Open existing segment."""
pass

def close(self):
"""Close the backend."""
pass

def commit(self):
"""Commit changes."""
pass

Registering a Backend​

from whoosh.registry import BackendRegistry

BackendRegistry.register("my_backend", MyBackend, "my_package")

Backend Selection​

Choose a backend based on your use case:

Use CaseRecommended Backend
Small to medium indexesFile (default)
Single-file deploymentSQLite
TestingMemory
Distributed systemsObject storage (S3, MinIO)
High concurrencySQLite or custom

Best Practices​

  1. File backend for production: Most battle-tested
  2. SQLite for single-file: Easier deployment
  3. Memory for tests: Fast, no cleanup needed
  4. Compound files: Enable for reduced file count
  5. Backup strategy: File backend = copy directory; SQLite = copy file