> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moorcheh.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch Text Data

> List text and summary chunks in a text namespace with cursor pagination using the Python SDK

## documents.fetch\_text\_data

Lists stored **text and summary chunks** for a **text** namespace. Use it for export, UI, or bulk RAG context loading.

Results are returned **one page at a time** (up to **100** items per page). When more data exists, the response includes `pagination.has_more` and `pagination.next_token` — pass that token on the next request to fetch the following page.

### Parameters

<ParamField path="namespace_name" type="str" required>
  The name of the target **text** namespace.
</ParamField>

<ParamField query="limit" type="int">
  Maximum number of items to return in this page. Must be between **1** and **100**. Omit to use the API default (**100**).
</ParamField>

<ParamField query="next_token" type="str">
  Opaque cursor from the previous response's `pagination.next_token`. Omit on the first request. Do not reuse a token from a different namespace or account.
</ParamField>

**Returns:** `FetchTextDataResponse` — keys are **snake\_case**: `status`, `message`, `namespace`, `statistics`, `items`, `pagination`, `execution_time`.

**Raises:** `NamespaceNotFound`, `InvalidInputError`, `AuthenticationError`, `APIError`.

### Example (sync, first page)

```python Fetch Text Data Example theme={null}
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    data = client.documents.fetch_text_data(namespace_name="my-faq-documents")

    print(data.get("status"), data.get("message"))
    pagination = data.get("pagination") or {}
    print("has_more:", pagination.get("has_more"))

    for item in data.get("items", []):
        print(item.get("id"), item.get("is_summary"), item.get("text", "")[:80])
```

### Example (async)

```python Fetch Text Data Async Example theme={null}
from moorcheh_sdk import AsyncMoorchehClient

async def main():
    async with AsyncMoorchehClient() as client:
        data = await client.documents.fetch_text_data(
            namespace_name="my-faq-documents",
            limit=100,
        )
        print(len(data.get("items", [])), "items on this page")

# asyncio.run(main())
```

### Pagination

<Steps>
  <Step title="First request">
    Call without `next_token` (optionally set `limit`, max 100).
  </Step>

  <Step title="Check pagination">
    If `pagination.has_more` is `true`, more chunks exist in the namespace.
  </Step>

  <Step title="Next page">
    Call again with `next_token` from the previous response.
  </Step>

  <Step title="Stop">
    Repeat until `pagination.has_more` is `false` or `next_token` is `null`.
  </Step>
</Steps>

Each page is a separate API call and counts toward your API request usage and credits.

```python Fetch all pages theme={null}
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    all_items = []
    next_token = None

    while True:
        page = client.documents.fetch_text_data(
            namespace_name="my-faq-documents",
            limit=100,
            next_token=next_token,
        )
        all_items.extend(page.get("items") or [])

        pagination = page.get("pagination") or {}
        if not pagination.get("has_more"):
            break
        next_token = pagination.get("next_token")

    print(f"Collected {len(all_items)} items across all pages")
```

### Response overview

* **`items`**: Text chunks for **this page** (length ≤ `limit`, max 100). Each item has `id`, `text`, optional `metadata`, `created_at` (ISO 8601 string or `null`), and `is_summary`.
* **`statistics`**: Aggregated counts for **this page only** — e.g. `total_items`, `total_text_chunks`, `total_summary_chunks`, `created_at_min`, `created_at_max`, `source_counts` (`created_at_min`/`created_at_max` may be `null`).
* **`pagination`**: `limit`, `has_more`, and `next_token` (`null` when there is no next page).
* **`message`**: Human-readable summary for **this page** (e.g. "Fetched N text items from namespace '...'").

### Complete example

```python Fetch Text Data Full Example theme={null}
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    listing = client.documents.fetch_text_data(
        namespace_name="my-faq-documents",
        limit=50,
    )
    print(listing.get("status"), listing.get("statistics"))
    print(listing.get("pagination"))

    for item in listing.get("items", []):
        print(item.get("id"), item.get("text", "")[:120])
```

## Important Notes

<Note>
  **Text namespaces only**: Vector-only namespaces are not supported for this route. The API returns an error if the namespace is not text-based.
</Note>

<Note>
  **Per-page statistics**: `statistics` describes only the items in the current `items` array, not the full namespace total.
</Note>

<Tip>
  **vs. Get Documents**: Use **`fetch_text_data`** to **list** chunks in the namespace (with pagination); use **`documents.get`** with a list of **`ids`** when you already know which documents to retrieve in full.
</Tip>

## Best practices

* Treat **`items`** as read-only chunks for display or export; use **Search** for similarity queries.
* Rely on **snake\_case** keys in Python (`is_summary`, `created_at`, `next_token`, etc.).
* Pass `limit` between 1 and 100; invalid values raise **`InvalidInputError`** before the request is sent.

## Related operations

* [Get Documents](/python-sdk/data/get-documents) - Retrieve specific documents by ID
* [Search](/python-sdk/search/query) - Semantic search over namespace content
* [Fetch Text Data (API)](/api-reference/data/fetch-text-data) - HTTP reference for the same endpoint
