Skip to main content
This package lets you integrate the Algolia Search API into your Django project. It’s based on the algoliasearch-client-python package. For an example, see algoliasearch-django-example.
  • Compatible with Python 3.8 or later.
  • Supports Django 4 and 5.

Install

pip install --upgrade 'algoliasearch-django>=4.0,<5.0'

Setup

In your Django settings, add algoliasearch_django to INSTALLED_APPS and add these two settings:
Python
ALGOLIA = {"APPLICATION_ID": "ALGOLIA_APPLICATION_ID", "API_KEY": "ALGOLIA_API_KEY"}
You can also add these optional settings:
  • INDEX_PREFIX A prefix for all indices. Use it to separate different applications, like site1_Products and site2_Products.
  • INDEX_SUFFIX A suffix for all indices. Use it to differentiate development and production environments, such as Location_dev and Location_prod.
  • AUTO_INDEXING If true (default), models are automatically synced with Algolia.
  • RAISE_EXCEPTIONS Raise exceptions for network errors instead of logging them (default to settings.DEBUG).

Quickstart

Create an index.py inside each application with the models you want to index. Inside this file, call algoliasearch.register() for each model you want to index:
Python
# index.py

import algoliasearch_django as algoliasearch

from .models import YourModel

algoliasearch.register(YourModel)
By default, all fields of your model are used. You can configure the index by creating a subclass of AlgoliaIndex and using the register decorator:
Python
# index.py

from algoliasearch_django import AlgoliaIndex
from algoliasearch_django.decorators import register

from .models import YourModel


@register(YourModel)
class YourModelIndex(AlgoliaIndex):
    fields = ("name", "date")
    geo_field = "location"
    settings = {"searchableAttributes": ["name"]}
    index_name = "my_index"

Connection errors

If you get one of these errors: Impossible to connect, Unable to connect, or Unreachable hosts:
  • Ensure you’re using the correct application ID and API key. You can find your credentials on your Algolia dashboard.
  • Check for recent changes in your code.
  • Check the status of your data center provider.
If you’re using Firebase, you can only access Algolia from a paid Firebase tier.
If you can’t solve the problem yourself, contact the Algolia support team and provide them with the following information:
  • The name of your framework integration (Django) and its version number
  • A code snippet to reproduce the issue
  • Error message or stack trace (if applicable)
  • The name of the Algolia index that’s causing problems
  • The exact UTC time of the event
  • If you can’t connect to the Algolia API from your browser, send the output from community.algolia.com/diag.
  • If you can’t connect to the Algolia API from your servers, send the output from the following command (run on any affected server):
    curl -sL https://algolia.com/downloads/diag.sh > ./diag.sh && sudo ./diag.sh ALGOLIA_APPLICATION_ID
    
Replace ALGOLIA_APPLICATION_ID with your Algolia application ID.

Indexing errors

Any Record at the position XX objectID=XX is too big errors during indexing are because you exceeded the size limit for records. Reduce the size of your records and try again.
I