Skip to main content

Django-Meili

A package to integrate Meilisearch with Django in a seamless way. This pacakge is tested on Meilisearch v1.24 - v1.31.

Install

pip install django_meili

Usage

Settings

Update your settings.py file to include the following:

INSTALLED_APPS = [
    # ...,  <--- Any 3rd Party code
    "django_meili",
    # ...,  <--- All your modules
]

# ....

MEILISEARCH = {}

You must define the django_meili application before any of your code that uses the application.

(NEW) Using djp

If you are using DJP as your django plugin manager, then you can simply install the application as normal. If you define your own custom settings, it will take priority over the current settings.

Example in Models

Update a model to include the following:

from django_meili.models import IndexMixin
from django.db import models

class Post(IndexMixin, models.Model):
    """Model definition for Post."""

    title = models.CharField(max_length=255)
    body = models.TextField()

    class Meta:
        """Meta definition for Post."""

        verbose_name = "Post"
        verbose_name_plural = "Posts"

    class MeiliMeta:
        filterable_fields = ("title",)
        searchable_fields = ("id", "title", "body")
        displayed_fields = ("id", "title", "body")

    def __str__(self):
        return self.title

Searching

Now you can search from meilisearch using Model.meilisearch:

Post.meilisearch.search("Hello World") # => <Queryset for Post>

API

MEILISEARCH in settings.py

These are the settings available to the package. The values show are the defaults.

MEILISEARCH = {
    'HTTPS': False, # Whether HTTPS is enabled for the meilisearch server
    'HOST': 'localhost', # The host for the meilisearch server
    'MASTER_KEY': None, # The master key for meilisearch. See https://www.meilisearch.com/docs/learn/security/basic_security for more detail
    'PORT': 7700, # The port for the meilisearch server
    'TIMEOUT': None, # The timeout to wait for when using sync meilisearch server
    'CLIENT_AGENTS': None, # The client agents for the meilisearch server
    'DEBUG': DEBUG, # Whether to throw exceptions on failed creation of documents
    'SYNC': False, # Whether to execute operations to meilisearch in a synchronous manner (waiting for each rather than letting the task queue operate)
    'OFFLINE': False, # Whether to make any http requests for the application.
    'DEFAULT_BATCH_SIZE': 1000, # For syncindex the default batch size for import queryset
}

django_meili.models.IndexMixin

The IndexMixin is how an index is defined on a model. To configure the IndexMixin define a class on the model called MeiliMeta. The IndexMixin defines two new properties on the model:

  1. meilisearch - The queryset used to search.
  2. _meilisearch - the MeiliMeta values available on the model.

In addition, the IndexMixin defines three methods:

  1. meili_filter() - Should this row be synced in meilisearch
  2. meili_serialize() - How the model is serialized into a dictionary
  3. meili_geo() - What does the _geo column look like (optional)

MeiliMeta

The listed values here are default values. The displayed, searchable, filterable, and sortable should all be iterables containing field names, see the example above.

class MeiliMeta:
    displayed_fields = None # the fields displayed when querying meilisearch
    searchable_fields = None # the searchable fields when querying meilisearch
    filterable_fields = None # the fields available to filter by using meilisearch
    sortable_fields = None # the fields that can be sorted by using meilisearch
    supports_geo = False # Does the model support geolocation
    index_name = "<model.__name__>" # the name of the meilisearch index
    primary_key = "pk" # the primary key field for the index

django_meili.querysets.IndexQuerySet

The queryset defines the searchable operations on the index. It attempts to mimic the django queryset API, but differs in 2 notable ways:

  1. To do geo-filtering, you pass a positional argument
  2. Not all queryset operations are implemented.

Commands

python manage.py syncindex

Sync the given index with the current database state. This will always be done synchronously.

python manage.py clearindex

Clear the given index. This will always be done synchronously.

Development

  1. clone the repo
  2. mise setup
  3. mise test
  4. Develop

Contact

If there are any issues, please feel free to make an issue. If you have suggested improvements, please make an issue where we can discuss.

Metadata

Release files for django-meili 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-meili 0.0.15
File Size Uploaded Provenance
django_meili-0.0.15.tar.gz 120.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-meili 0.0.15
File Interpreter ABI Platform
django_meili-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 138.4 kB

Release files / django_meili-0.0.15.tar.gz

Download URL django_meili-0.0.15.tar.gz
Size 120.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9169c73d7a49b7290559062a3d7d5b7e84678ce2fce3a16a7eb1197470bfc60c
BLAKE2b-256 checksum
How to use checksums
4c3b005751a6fdbc22b6d238963fda59c93276777ac08eec5188cb074b23b176
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Release files / django_meili-0.0.15-py3-none-any.whl

Download URL django_meili-0.0.15-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3f34c4265af93db68bd83ff2e1e6f0789e8f20a047be2ea41208ddb6adc4c6a
BLAKE2b-256 checksum
How to use checksums
9d37baccccacbf396952030bed454cca5cd6f0e81e6b7e0a0120ecf05cf60d23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Security for django-meili 0.0.15

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.

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