Skip to main content

Qx search: OpenSearch/Elasticsearch async client, repository abstraction, index lifecycle helpers (V2 stub)

Project description

qx-search

OpenSearch/Elasticsearch async client and repository abstraction for the Qx framework.

What lives here

  • qx.search.SearchRepository[TDoc] — abstract base class for document repositories. Implement index_name and to_document / from_document mapping; the base provides index, get, delete, and search methods.
  • qx.search.SearchQuery — composable query builder: full-text query, filters, sort, pagination offset, and highlight options.
  • qx.search.SearchHit[TDoc] — single search result with the mapped document, score, and raw _source.
  • qx.search.SearchSettings — Pydantic settings for the OpenSearch/Elasticsearch endpoint URL and optional auth.
  • qx.search.create_search_client — async factory that opens an AsyncOpenSearch connection.
  • qx.search.ensure_index / drop_index — index lifecycle helpers; ensure_index creates an index with provided mapping if it doesn't exist (idempotent).

Usage

from qx.search import SearchRepository, SearchQuery, SearchSettings, create_search_client

class ProductSearchRepository(SearchRepository[ProductDoc]):
    index_name = "products"

    def to_document(self, product: Product) -> dict:
        return {"id": str(product.id), "name": product.name, "sku": product.sku}

    def from_document(self, doc: dict) -> ProductDoc:
        return ProductDoc(**doc)


# Bootstrap
client = await create_search_client(settings.search)
repo = ProductSearchRepository(client)

# Index a document
await repo.index(product)

# Search
hits = await repo.search(SearchQuery(q="widget", filters={"category": "tools"}, size=20))

Design rules

  • SearchRepository intentionally does not extend qx.db.Repository — search is a read projection, not the system of record. Write to the DB first, sync to search via an integration event handler.
  • ensure_index is safe to call at startup on every deploy; it is a no-op if the index already exists with a compatible mapping.
  • This package is a V2 scope item. The InMemorySearchRepository test double lives in qx-testing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qx_search-1.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qx_search-1.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file qx_search-1.1.0.tar.gz.

File metadata

  • Download URL: qx_search-1.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qx_search-1.1.0.tar.gz
Algorithm Hash digest
SHA256 bb266dad4d92e92604480850622ee9efa92870937a0b654add2c6faf565c837a
MD5 fa04620f890435aef5c444e7ea7c2c02
BLAKE2b-256 017b9e7e0fa0e2a725045445459104b69f42f35d98e04e51951621967a4858e6

See more details on using hashes here.

File details

Details for the file qx_search-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: qx_search-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qx_search-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 146443705a763ee26a8ef3fcfb3858bc31345c504982df6c3519488402216fb5
MD5 094b6a574da6c15cb3b106e5709cff18
BLAKE2b-256 d56782274ef978c87a900ddf6875abf579f07db310ce3085cd9cebf31097507f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page