django-opensearch-toolkit
A Django app to facilitate interacting with OpenSearch clusters, including connection management, migrations, and unit tests.
It is implemented as a thin wrapper over the opensearch-py library for connection management and DSL operations, and benefits from all functionality it provides. The only other dependency is Django itself.
Some key advantages to using this app:
- Configure connections to multiple clusters using the Django settings module
- This is analogous to how Django manages connections to multiple RDBMS databases.
- Define cluster state (e.g., ISM policies, index template mappings, indices) in code, via migration files
- This makes it easier to track and replicate these settings across environments (e.g., dev & prod clusters).
- This is analogous to how Django generates migration files for schema changes. The difference is that the migrations here are manually written, not auto-generated. They can be written using the DSL of the OpenSearch Python client.
- Run migrations against clusters using Django management commands
- This is analogous to running
python manage.py migratefor RDBMS databases. - Under the hood, it tracks the state of migrations in a hidden index in the cluster itself to avoid running migrations multiple times, similar to what Django does using tables in relational dbs.
- This is analogous to running
- Write cleaner unit tests with helpful test runners and mocks
Quick Start
- Install the package:
pip install django-opensearch-toolkit
- Add this app to your Django project's list of installed apps:
# settings.py
INSTALLED_APPS = [
...
"django_opensearch_toolkit",
...
]
- Define the cluster(s) to configure:
# settings.py
OPENSEARCH_CLUSTERS = {
# cluster_name -> configuration
# This dict is passed to opensearchpy.connection.configure() while the
# Django environment is being initialized.
"sample_app": {
"hosts": [
{
"host": "localhost",
"port": 9200,
}
],
"timeout": 30,
},
}
- Register migrations for each cluster
# settings.py
OPENSEARCH_MIGRATION_PATHS = {
# cluster_name -> module_path
# - Each module should define a variable named MIGRATIONS.
# - The module will be dynamically imported and the MIGRATIONS variable will be used.
"sample_app": "sample_app.opensearch_migrations",
}
-
Implement your migrations and ensure they are discoverable at the paths indicated in the previous step. See the
sample_project/sample_app/opensearch_migrations/__init__.pyfor an example.- NOTE: Currently, we only support a dependency chain, instead of a more generic dependency graph, like Django does for its migrations.
-
Display and run your migrations.
- This requires a running OpenSearch cluster at localhost:9200 (configured in step 3).
cd sample_project
python manage.py opensearch_displaymigrations sample_app
python manage.py opensearch_runmigrations sample_app
python manage.py opensearch_runmigrations sample_app --nodry
python manage.py opensearch_displaymigrations sample_app
Local Development
From the project root, run:
./scripts/setup_dev.sh # Creates a virtual environment in the project directory & downloads all requirements
source venv/bin/activate # Step into your virtual environment
make test # Confirm all tests pass
make check # Confirm all static checks pass
make integration-test # Run an integration test (requires docker daemon to be running)
deactivate # Leave your virtual environment
Metadata
Release files for django-opensearch-toolkit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_opensearch_toolkit-0.1.0.tar.gz | 13.9 kB | Without provenance | Details for django_opensearch_toolkit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_opensearch_toolkit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_opensearch_toolkit-0.1.0-py3-none-any.whl |
Total release size: 29.8 kB
Release files / django_opensearch_toolkit-0.1.0.tar.gz
| Download URL | django_opensearch_toolkit-0.1.0.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a67fb2602db577404ae64518b23b5d99ff04b2744d3950d152926683aedbcf9
|
|
BLAKE2b-256 checksum How to use checksums |
f8c32ee9f40d5d2973864061867af4f71c14423fc27b9fe0194f7b74a5edb2ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Release files / django_opensearch_toolkit-0.1.0-py3-none-any.whl
| Download URL | django_opensearch_toolkit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
076922a255b76a91be273b2a9058b6a9552b4a84c28b62bf6665d920cce045cc
|
|
BLAKE2b-256 checksum How to use checksums |
a2be7723d5a66daf54b5434bcbd74b9ec84a6705a057b0634e7a48e0695dbe10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Security for django-opensearch-toolkit 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.