Install & Compatibility
Where this runs
tested against v4.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 66.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.5s · import 0.000s · 67MB
66MB installed
● package 66MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
algoliasearch
✓ import algoliasearch_django as algoliasearch
✗ import algoliasearch_django as algoliasearch
To get started, first configure your Algolia credentials in your Django `settings.py` under an `ALGOLIA` dictionary. Then, define your Django models. Finally, create an `index.py` file within your app and register your models for indexing using either `algoliasearch.register()` or the `@register` decorator with a subclass of `AlgoliaIndex` to specify index settings and fields. Remember to add `algoliasearch_django` to your `INSTALLED_APPS`.
import os
import django
from django.conf import settings
from django.db import models
# Configure Django settings minimally for standalone execution
if not settings.configured:
settings.configure(
INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.contenttypes',
'myapp',
'algoliasearch_django'
],
DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}},
ALGOLIA={
'APPLICATION_ID': os.environ.get('ALGOLIA_APPLICATION_ID', 'YOUR_APP_ID'),
'API_KEY': os.environ.get('ALGOLIA_API_KEY', 'YOUR_API_KEY'),
'INDEX_PREFIX': 'dev_',
},
DEFAULT_AUTO_FIELD='django.db.models.AutoField',
SECRET_KEY='a-very-secret-key',
DEBUG=True
)
django.setup()
# models.py (example in a fictional 'myapp')
class Product(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
price = models.DecimalField(max_digits=10, decimal_places=2)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
class Meta:
app_label = 'myapp'
# index.py (example in 'myapp')
from algoliasearch_django import AlgoliaIndex
from algoliasearch_django.decorators import register
@register(Product)
class ProductIndex(AlgoliaIndex):
fields = ('name', 'description', 'price', 'created_at')
settings = {'searchableAttributes': ['name', 'description'], 'attributesForFaceting': ['price']}
# You can customize `get_attribute_name` or `get_extra_attributes` for more complex indexing
# --- Example Usage (after defining models and index, typically run via manage.py) ---
# This part would typically be run via `python manage.py shell` or a management command.
# For demonstration, we simulate creating and saving an object.
# In a real Django app, signals handle auto-indexing on save.
# Create a product (this would automatically index if AUTO_INDEXING is True, which is default)
# from myapp.models import Product
# p1 = Product.objects.create(name="Wireless Headphones", description="High-quality audio experience.", price=199.99)
# p2 = Product.objects.create(name="Bluetooth Speaker", description="Portable and powerful sound.", price=79.99)
# print("Products created and indexed.")
# To manually reindex all: python manage.py algolia_reindex
# To apply settings: python manage.py algolia_applysettings
print("Algolia Django integration configured. To index data, run 'python manage.py algolia_reindex' or save model instances.")
Upgrade
Version history
4.0.0latest on PyPI · released Jan 6, 2025
Audit
Dependencies
DjangorequiredCore framework dependency, requires Django>=4.0 for algoliasearch-django v4.
algoliasearchrequiredUnderlying Algolia Python API client, requires algoliasearch>=4.0,<5.0.