Add support for export api
Pull Request
Added support for the Export API as described in the official Meilisearch docs.
- Add the new methods to interact with the Meilisearch API
- Add new tests cases
- Write an example code in .code-samples.meilisearch.yaml under the export_post_1 key
Related issue
Fixes # 1129
PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
-
New Features
- Added cross-instance data export between Meilisearch servers with optional index filtering and configurable payload sizing.
-
Tests
- Added end-to-end tests validating export behavior across two Meilisearch servers, including full and filtered exports and result verification.
-
Chores
- Added support for a secondary local Meilisearch instance and updated test setup/teardown to operate across both instances.
βοΈ Tip: You can customize this high-level summary in your review settings.
Walkthrough
Adds an exports path and a new Client.export(...) method, introduces a second Meilisearch instance and client support in tests (client2), adds end-to-end export tests against the secondary instance, and provides a code sample demonstrating an export request.
Changes
| Cohort / File(s) | Summary |
|---|---|
Client API & Configmeilisearch/client.py, meilisearch/config.py |
Added Client.export(url: str, api_key: Optional[str]=None, payload_size: Optional[str]=None, indexes: Optional[Mapping[str,Any]]=None) -> TaskInfo which builds a payload (url + optional fields) and POSTs to the exports endpoint; added Config.Paths.exports = "export". |
Compose & Test env constantsdocker-compose.yml, tests/common.py |
Added second Meilisearch service meilisearch2 and MEILISEARCH_URL_2 env var in compose; added BASE_URL_2 (from MEILISEARCH_URL_2, default http://127.0.0.1:7701) for tests. |
Test fixturestests/conftest.py |
Added client2 session fixture; updated clear_indexes and clear_all_tasks to accept client2 and clear indexes/tasks on the secondary instance when configured; added helper _clear_indexes(meilisearch_client) and imported os. |
Export teststests/client/test_client_exports.py |
Added test_export_creation and test_export_creation_with_index_filter, gated by MEILISEARCH_URL_2, which create exports on source, wait for completion, and verify exported indexes (UID, primary key, document counts) on the secondary server. |
Code samples.code-samples.meilisearch.yaml |
Added export_post_1 sample under post_dump_1 demonstrating an export call with remote URL, API key, payload size, and an indexes map (movies*, books*). |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant Test as Test runner
participant Client as Client.export()
participant Source as Meilisearch A
participant Target as Meilisearch B
Test->>Client: call export(url, api_key, payload_size, indexes)
activate Client
Client->>Client: build payload (url + optional fields)
Client->>Source: POST /exports (payload)
activate Source
Source-->>Client: TaskInfo (task created)
deactivate Source
Client-->>Test: return TaskInfo
deactivate Client
Note right of Test: Poll task until completion
Test->>Target: Query indexes / index details
activate Target
Target-->>Test: index metadata & document counts
deactivate Target
Note over Test,Target: Verify UID, primary key, document count match source
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~25 minutes
- Areas to inspect closely:
- Payload field names and serialization in
Client.exportvs API expectations (e.g.,payloadSize,apiKey,indexesshape). - Task response handling and TaskInfo construction in
meilisearch/client.py. - Fixture lifecycle and conditional clearing logic for
client2intests/conftest.py. - Test timing/polling and assertions in
tests/client/test_client_exports.py. - docker-compose additions for potential port/env conflicts.
- Payload field names and serialization in
Poem
π I hopped a payload across the stream,
Packed URLs, keys, and index dream.
Two servers hummed β one, then two,
Tests checked the carrots through and through.
A tiny hop, an export gleam.
Pre-merge checks and finishing touches
β Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | β Passed | The PR title clearly and concisely summarizes the main change: adding support for the Export API. It accurately reflects the primary objective of the changeset across all modified files. |
| Docstring Coverage | β Passed | Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%. |
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
β¨ Finishing touches
- [ ] π Generate docstrings
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
@Strift not sure whether we should wait for https://github.com/meilisearch/meilisearch/issues/6009 or let it go. Locally I was experiencing the same issue and it took quite of my time but here test cases are passing.
Hi @jawad-khan and thanks for this PR π
It's best to hold off until the issue is fixed. Otherwise, we would just be setting ourselves up to get reports in this repository that are unrelated to the SDK π