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.x
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.1.0.tar.gz (40.1 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.1.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_opensearch_models-1.1.0.tar.gz
  • Upload date:
  • Size: 40.1 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.1.0.tar.gz
Algorithm Hash digest
SHA256 6d065f3734a23c73b5d8508e34cf947682c002f3fefa2cc8172e9ba217ba37a3
MD5 bd6d6c9a7cfb98456f7c4ae317d3f573
BLAKE2b-256 d2989f2ea080a59907b856f8aa9ad6650093bc96ce47dcb5e20858d6c134e2a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_opensearch_models-1.1.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.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_opensearch_models-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7cc857411729c3873795c4bae741fa1cfeb642e1f1a0139ab9b6fd8189a85d2
MD5 dac3238cd7ead7fa90de6caa18abd8ce
BLAKE2b-256 9f86aa21718e372273fd1b00946922642e7fcaf2370fa19a49505d5d53ac7910

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_opensearch_models-1.1.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

1.2.0

2 files

This release

1.1.0 This release

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