SDKs overview
Meilisearch offers a suite of official SDKs and supports community-contributed libraries to facilitate integration with its search engine. These SDKs are designed to provide a developer-friendly interface to the Meilisearch API, abstracting the complexities of HTTP requests and JSON parsing. By using an SDK, developers can interact with a Meilisearch instance to perform operations such as adding or updating documents, configuring search settings, and executing search queries directly from their preferred programming language environment.
The primary benefit of using an SDK is the reduction in development time and effort. SDKs typically handle common tasks such as API key management, error handling, and request/response serialization. This allows developers to focus on application logic rather than the intricacies of the API itself. Meilisearch maintains official SDKs for many popular programming languages, ensuring up-to-date and well-supported integration pathways for its users. The Meilisearch documentation provides comprehensive guides for each official SDK, detailing installation, configuration, and usage examples for various search operations and index management tasks Meilisearch SDKs overview.
Official SDKs by language
Meilisearch provides official client libraries that offer idiomatic ways to interact with the Meilisearch API from different programming languages. These libraries are developed and maintained by the Meilisearch team, ensuring compatibility with the latest engine features and robust performance. Each SDK is designed to reflect the best practices of its respective language, providing a natural development experience.
The following table lists the official SDKs, their package names, typical installation commands, and their general maturity level as indicated by Meilisearch:
| Language | Package/Module Name | Installation Command | Maturity |
|---|---|---|---|
| JavaScript | meilisearch |
npm install meilisearch or yarn add meilisearch |
Stable |
| PHP | meilisearch/meilisearch-php |
composer require meilisearch/meilisearch-php |
Stable |
| Python | meilisearch |
pip install meilisearch |
Stable |
| Ruby | meilisearch |
gem install meilisearch |
Stable |
| Go | github.com/meilisearch/meilisearch-go |
go get github.com/meilisearch/meilisearch-go |
Stable |
| Java | com.meilisearch:meilisearch-java |
Maven: add dependency; Gradle: add implementation | Stable |
| C# | Meilisearch |
dotnet add package Meilisearch |
Stable |
| Rust | meilisearch-sdk |
Add to Cargo.toml dependencies |
Stable |
| Dart | meilisearch |
dart pub add meilisearch |
Stable |
| Swift | MeilisearchNIO |
Add as Swift Package Dependency | Stable |
Each SDK provides methods that map directly to the Meilisearch RESTful API endpoints, allowing for operations such as index creation, document batching, search querying, and managing various index settings like ranking rules, synonyms, and stop words. Developers can refer to the specific SDK documentation for detailed API method signatures and usage examples, available via the main Meilisearch SDKs documentation.
Installation
Installing a Meilisearch SDK typically involves using the package manager specific to the programming language. The process is generally straightforward, requiring a single command to add the library to a project's dependencies. Before installing an SDK, ensure that the appropriate language runtime and package manager are set up in your development environment.
JavaScript (Node.js/Browser)
npm install meilisearch
# or
yarn add meilisearch
PHP (Composer)
composer require meilisearch/meilisearch-php
Python (pip)
pip install meilisearch
Ruby (Bundler/gem)
gem install meilisearch
Go (go get)
go get github.com/meilisearch/meilisearch-go
Java (Maven/Gradle)
For Maven, add the following to your pom.xml:
<dependency>
<groupId>com.meilisearch</groupId>
<artifactId>meilisearch-java</artifactId>
<version>[latest_version]</version>
</dependency>
For Gradle, add to your build.gradle:
implementation 'com.meilisearch:meilisearch-java:[latest_version]'
C# (.NET CLI)
dotnet add package Meilisearch
Rust (Cargo)
Add to your Cargo.toml:
[dependencies]
meilisearch-sdk = "[latest_version]"
Dart (pub)
dart pub add meilisearch
Swift (Swift Package Manager)
Add as a dependency in Xcode or your Package.swift file:
.package(url: "https://github.com/meilisearch/meilisearch-swift.git", from: "[latest_version]")
After installation, the SDK can be imported and initialized in your application code. Most SDKs require the Meilisearch host URL and an API key (if security is enabled) for initialization. For example, the Meilisearch API keys documentation provides guidance on securing your instance Meilisearch API Keys.
Quickstart example
This example demonstrates how to initialize the Meilisearch client, add documents to an index, and perform a basic search using the JavaScript SDK. This pattern is broadly similar across other official SDKs, with syntax adjusted for the specific language.
JavaScript Quickstart
First, ensure you have a Meilisearch instance running, either locally or in the cloud. You can start a local instance using Docker: docker run -p 7700:7700 -e MEILI_MASTER_KEY='aStrongMasterKey' getmeili/meilisearch:latest.
const { Meilisearch } = require('meilisearch');
(async () => {
const client = new Meilisearch({
host: 'http://localhost:7700',
apiKey: 'aStrongMasterKey', // Replace with your actual master key or a search key
});
const index = client.index('movies');
// Add documents to the index
const documents = [
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
{ id: 2, title: 'Little Miss Sunshine', genres: ['Comedy', 'Drama'] },
{ id: 3, title: 'Arrival', genres: ['Science Fiction', 'Drama'] },
{ id: 4, title: 'Blade Runner 2049', genres: ['Science Fiction', 'Drama'] },
{ id: 5, title: 'The Matrix', genres: ['Science Fiction', 'Action'] },
];
try {
console.log('Adding documents...');
const addDocsTask = await index.addDocuments(documents);
await client.waitForTask(addDocsTask.taskUid);
console.log('Documents added successfully.');
// Perform a search
console.log('Searching for "drama"...');
const searchResults = await index.search('drama');
console.log('Search Results:', searchResults.hits);
// Search with options
console.log('Searching for "science fiction" with limit...');
const searchWithOptions = await index.search('science fiction', {
limit: 1,
attributesToRetrieve: ['title'],
});
console.log('Search Results (limited):', searchWithOptions.hits);
} catch (error) {
console.error('Error with Meilisearch operation:', error);
}
})();
This example first initializes the Meilisearch client, then creates an index named movies. It proceeds to add a set of movie documents to this index and then performs two different search queries. The waitForTask method is crucial for asynchronous operations like adding documents, ensuring the index is updated before subsequent searches are performed. Further details on specific search parameters and index configurations are available in the Meilisearch Search API reference.
For more complex use cases, developers may configure index settings such as ranking rules, searchable attributes, and filters to optimize search relevance. These settings are also manageable through the SDKs, providing fine-grained control over the search experience. The ability to customize these aspects is a key feature of modern search engines like Meilisearch, enhancing the user experience by delivering highly relevant results, as highlighted by resources on effective API design Google API Design Guide.
Community libraries
Beyond the official SDKs, the Meilisearch ecosystem includes various community-contributed libraries and integrations. These libraries extend Meilisearch's reach into frameworks, content management systems, and other specialized environments not covered by official support. Community contributions can range from plugins for popular web frameworks, like Laravel or Ruby on Rails, to integrations with static site generators or e-commerce platforms.
While community libraries can offer valuable convenience and tailored solutions, developers should evaluate their maturity, maintenance status, and compatibility with the specific Meilisearch engine version they are using. They may not always be as up-to-date or as rigorously tested as the official SDKs. However, they can often fill specific niche requirements and accelerate development for particular tech stacks. Developers interested in contributing to or utilizing community projects can often find them listed in the Meilisearch documentation or on community forums and GitHub. It's recommended to check the official Meilisearch SDKs and Integrations page for a curated list of community resources.