django-opensearch-models
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
Documentsubclass 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_modelsand edits to aForeignKeytarget 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_indexsignal - Fields — field types, relationships and custom mappings
- Settings — every setting the app reads
- Commands — the
search_indexmanagement 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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d065f3734a23c73b5d8508e34cf947682c002f3fefa2cc8172e9ba217ba37a3
|
|
| MD5 |
bd6d6c9a7cfb98456f7c4ae317d3f573
|
|
| BLAKE2b-256 |
d2989f2ea080a59907b856f8aa9ad6650093bc96ce47dcb5e20858d6c134e2a1
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_opensearch_models-1.1.0.tar.gz -
Subject digest:
6d065f3734a23c73b5d8508e34cf947682c002f3fefa2cc8172e9ba217ba37a3 - Sigstore transparency entry: 2620637493
- Sigstore integration time:
-
Permalink:
django-opensearch/django-opensearch-models@edfb9818ccfbd8465b5af0513e40f0674f25e494 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/django-opensearch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@edfb9818ccfbd8465b5af0513e40f0674f25e494 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_opensearch_models-1.1.0-py3-none-any.whl.
File metadata
- Download URL: django_opensearch_models-1.1.0-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7cc857411729c3873795c4bae741fa1cfeb642e1f1a0139ab9b6fd8189a85d2
|
|
| MD5 |
dac3238cd7ead7fa90de6caa18abd8ce
|
|
| BLAKE2b-256 |
9f86aa21718e372273fd1b00946922642e7fcaf2370fa19a49505d5d53ac7910
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_opensearch_models-1.1.0-py3-none-any.whl -
Subject digest:
e7cc857411729c3873795c4bae741fa1cfeb642e1f1a0139ab9b6fd8189a85d2 - Sigstore transparency entry: 2620637665
- Sigstore integration time:
-
Permalink:
django-opensearch/django-opensearch-models@edfb9818ccfbd8465b5af0513e40f0674f25e494 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/django-opensearch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@edfb9818ccfbd8465b5af0513e40f0674f25e494 -
Trigger Event:
push
-
Statement type: