meilisearch-python icon indicating copy to clipboard operation
meilisearch-python copied to clipboard

Add support for export api

Open jawad-khan opened this issue 2 months ago β€’ 3 comments

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.

jawad-khan avatar Nov 26 '25 08:11 jawad-khan

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 & Config
meilisearch/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 constants
docker-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 fixtures
tests/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 tests
tests/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.export vs API expectations (e.g., payloadSize, apiKey, indexes shape).
    • Task response handling and TaskInfo construction in meilisearch/client.py.
    • Fixture lifecycle and conditional clearing logic for client2 in tests/conftest.py.
    • Test timing/polling and assertions in tests/client/test_client_exports.py.
    • docker-compose additions for potential port/env conflicts.

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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 26 '25 08:11 coderabbitai[bot]

@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.

jawad-khan avatar Nov 26 '25 08:11 jawad-khan

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 πŸ˜…

Strift avatar Nov 27 '25 07:11 Strift