Skip to main content
The algoliasearch-django package connects your Django models to Algolia. It uses Django signals to update your Algolia index when you create, update, or delete records. It also adds a raw_search function to query your indices. The package builds on the Algolia API client for Python. The package is open source and available on GitHub. For a sample Django app with Autocomplete and InstantSearch results pages, see the algoliasearch-django-example repository.

Before you begin

You need:

Set up the package

Set up the package in a new Django project. Then index and search a record.
1

Create a Django project

To create a new Django project with a contacts app, run:
2

Install the package

To install the package and the Algolia API client for Python, run:
3

Configure the package

In algolia_demo/settings.py, add algoliasearch_django and contacts to INSTALLED_APPS. Then add the ALGOLIA setting:
algolia_demo/settings.py
Replace ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY with your Algolia credentials. Find both in the Algolia dashboard. To run this test, use an API key with the search and addObject ACLs.
To create Algolia applications and API keys from the command line, use the Algolia CLI.
4

Create a model

To create a Contact model and its database table, replace the contents of contacts/models.py:
contacts/models.py
To create the database table, generate and apply the migration, run:
5

Connect the model to Algolia

To send your model to Algolia, register it in an index.py file in your app. The package finds this file when Django starts. It sets up your and options. An empty subclass of AlgoliaIndex sets up the default options.Create contacts/index.py:
contacts/index.py
Replace INDEX_NAME with the name of a new test index. Without index_name, the package uses the model name.
6

Index and search a record

To add a record and search for it, run:
If the setup works, the command prints ['Jon Doe']. Each write waits for Algolia to finish indexing, so the record is searchable right away. Each run adds another record to your test index. To remove the indexed test records, delete the index in the Algolia dashboard or with the Algolia CLI. This also deletes the index settings. The test contacts are stored separately in your Django database.

Use optional settings

Besides APPLICATION_ID and API_KEY, the ALGOLIA setting accepts these optional properties:
  • INDEX_PREFIX A prefix for all indices. Use it to separate different indices, 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 (defaults to the value of settings.DEBUG).

Configure your index

Algolia indexes all model fields by default. To change which fields you index, or to set index settings, add attributes to your AlgoliaIndex subclass:
Python
To register a model with the default index options, call register as a function:
Python
For all index options, see Options.

Next steps

  • Commands: reindex, clear, and apply settings from the command line
  • Search: build a search experience for your Django app
  • Troubleshooting: fix connection and indexing errors
Last modified on November 27, 2026