Meilisearch Python SDK

raw JSON →
7.1.3 verified Fri May 01 auth: no python

A Python client providing both async and sync support for the Meilisearch API. The SDK simplifies interacting with Meilisearch, an open-source, fast, and relevant search engine. Current version 7.1.3 supports Python >=3.10 and features both synchronous and asynchronous clients.

pip install meilisearch-python-sdk
error ModuleNotFoundError: No module named 'meilisearch'
cause Old package name not installed; package renamed to meilisearch-python-sdk
fix
pip install meilisearch-python-sdk
error ImportError: cannot import name 'Client' from 'meilisearch_python_sdk'
cause Sync client moved to 'meilisearch_python_sdk.sync_client'
fix
Use 'from meilisearch_python_sdk.sync_client import Client'
error AttributeError: 'Client' object has no attribute 'index'
cause Using old 'meilisearch' package's API. New SDK uses 'client.index(index_name)' on the client instance directly.
fix
Use 'index = client.index('movies')' (no need to get/index via request).
breaking Version 7.0 changed the package name from 'meilisearch' to 'meilisearch-python-sdk' and the import path uses 'meilisearch_python_sdk'. Old code with 'meilisearch' will break.
fix Install meilisearch-python-sdk and update imports to 'from meilisearch_python_sdk import ...'
gotcha The async client requires an async context manager or explicit closing. Not closing the client can cause resource leaks.
fix Use 'async with AsyncMeilisearchClient(...) as client:' or call 'await client.close()'.
gotcha The sync client's Client class is in 'meilisearch_python_sdk.sync_client', not at the top level of the package.
fix Import as: 'from meilisearch_python_sdk.sync_client import Client'

Initialize sync client, add documents to an index.

from meilisearch_python_sdk import MeilisearchClient

client = MeilisearchClient('http://localhost:7700', 'masterKey')
index = client.index('movies')
documents = [
    { 'id': 1, 'title': 'Carol', 'genres': ['Romance', 'Drama'] },
    { 'id': 2, 'title': 'Wonder Woman', 'genres': ['Action', 'Adventure'] }
]
result = index.add_documents(documents)
print(result)