Documentation Index
Fetch the complete documentation index at: https://www.meilisearch.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
This guide walks you through setting up Meilisearch with Python.
Prerequisites
1. Install the SDK
2. Connect to Meilisearch
import meilisearch
import os
client = meilisearch.Client(
os.environ.get('MEILISEARCH_URL'),
os.environ.get('MEILISEARCH_KEY')
)
Set your environment variables:export MEILISEARCH_URL="https://your-instance.meilisearch.io" # or http://localhost:7700
export MEILISEARCH_KEY="your_api_key"
Get a free Cloud instance →
3. Add documents
movies = [
{'id': 1, 'title': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'year': 1999},
{'id': 2, 'title': 'Inception', 'genres': ['Action', 'Thriller'], 'year': 2010},
{'id': 3, 'title': 'Interstellar', 'genres': ['Drama', 'Sci-Fi'], 'year': 2014}
]
# Add documents to the 'movies' index
task = client.index('movies').add_documents(movies)
# Wait for indexing to complete
client.wait_for_task(task.task_uid)
4. Search
results = client.index('movies').search('matrix')
print(results['hits'])
# [{'id': 1, 'title': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'year': 1999}]
5. Search with filters
First, configure filterable attributes:
client.index('movies').update_filterable_attributes(['genres', 'year'])
Then search with filters:
results = client.index('movies').search('', {
'filter': 'genres = "Sci-Fi" AND year > 2000'
})
Full example
import meilisearch
import os
client = meilisearch.Client(
os.environ.get('MEILISEARCH_URL'),
os.environ.get('MEILISEARCH_KEY')
)
# Add documents
movies = [
{'id': 1, 'title': 'The Matrix', 'genres': ['Action', 'Sci-Fi'], 'year': 1999},
{'id': 2, 'title': 'Inception', 'genres': ['Action', 'Thriller'], 'year': 2010},
{'id': 3, 'title': 'Interstellar', 'genres': ['Drama', 'Sci-Fi'], 'year': 2014}
]
task = client.index('movies').add_documents(movies)
client.wait_for_task(task.task_uid)
# Search
results = client.index('movies').search('inter')
print(results['hits'])
Next steps
Full-text search
Configure ranking and relevancy
Filtering
Add filters and facets
AI-powered search
Add semantic search
API reference
Explore all search parameters
Resources