Skip to main content

django-opensearch-models

CI Coverage PyPI Python Docs License Ruff

Index your Django models in OpenSearch and keep them in sync automatically.

You describe an index by declaring a Document class against a model, and the library handles the rest: it builds the OpenSearch mapping from your Django fields, populates the index, and updates it on every save() and delete() through Django's signal framework. Search results convert back into real Django querysets when you need them.

What you get

  • Declarative documents. A Document subclass maps a Django model to an OpenSearch index — fields, analyzers, index settings and all.
  • Automatic synchronisation. Model changes reach the index through signals, either inline or handed to Celery as background tasks.
  • Related-model tracking. Declare related_models and edits to a ForeignKey target re-index the documents that embed it.
  • Management commands. Create, populate, rebuild and delete indices, with zero-downtime rebuilds behind an alias and optional parallel indexing.
  • Querysets from search results. .to_queryset() turns a search response back into a Django queryset, ordered to match the search.

Requirements

Supported versions
Python 3.12, 3.13, 3.14
Django 5.2, 6.0, 6.1
opensearch-py >=3.1, <4
OpenSearch server 2.19, 3.8

Every combination in that table is exercised nightly against a real OpenSearch cluster, under both signal processors.

Installation

$ pip install django-opensearch-models

Quick start

Add the app and point it at your cluster:

# settings.py

INSTALLED_APPS = [
    ...,
    "django_opensearch_models",
]

OPENSEARCH = {
    "default": {
        "hosts": "localhost:9200",
        "http_auth": ("username", "password"),
    },
}

Declare a document for the model you want to index, in your app's documents.py:

# documents.py

from django_opensearch_models import Document
from django_opensearch_models.registries import registry

from .models import Car


@registry.register_document
class CarDocument(Document):
    class Index:
        name = "cars"
        settings = {"number_of_shards": 1, "number_of_replicas": 0}

    class Django:
        model = Car
        fields = ["name", "color", "description"]

Build the index:

$ ./manage.py search_index --rebuild

From here on, saving a Car indexes it. Searching returns OpenSearch hits, or Django objects:

hits = CarDocument.search().filter("term", color="red")

for hit in hits:
    print(hit.name, hit.description)

# ...or come back to the ORM
cars = CarDocument.search().filter("term", color="red")[:30].to_queryset()

Documentation

Full documentation is at django-opensearch-models.readthedocs.io.

  • Quickstart — install, configure, index and search
  • Indices — index objects, aliases and the post_index signal
  • Fields — field types, relationships and custom mappings
  • Settings — every setting the app reads
  • Commands — the search_index management command
  • Contributing — running the tests and the support matrix

Contributing

Issues and pull requests are welcome at github.com/django-opensearch/django-opensearch-models. See the contributing guide for how to run the test suite against a throwaway OpenSearch container.

License

Apache-2.0. See LICENSE and NOTICE.

Download files

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

Source Distribution

django_opensearch_models-1.2.0.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

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

django_opensearch_models-1.2.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file django_opensearch_models-1.2.0.tar.gz.

File metadata

  • Download URL: django_opensearch_models-1.2.0.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_opensearch_models-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4fb692e13fb043d9f8d6b831ff4124601409b211a39b59ea1ea5e0f4e7fba424
MD5 fce5ca5c878ecf6309769249650e0643
BLAKE2b-256 3e7d5d1e33869ef6ff9430fee7eddbc9842123be6ad407e5dd3040327c9a8a17

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_opensearch_models-1.2.0.tar.gz:

Publisher: release.yml on django-opensearch/django-opensearch-models

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_opensearch_models-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_opensearch_models-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f5c95c83f968a430975b7b136ebaf489b4d818a54ce6f682a349ef4d151753f
MD5 304e754e8e1f0e052c3ee4c129540a64
BLAKE2b-256 0006c1ffc6a87137e709f12b3852edb1a58c1fa5c2e2608381e4df1b48eeea18

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_opensearch_models-1.2.0-py3-none-any.whl:

Publisher: release.yml on django-opensearch/django-opensearch-models

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 files

1.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page