---
source_url: https://www.pubnub.com/docs/sdks/asyncio/api-reference/message-persistence-legacy
title: "Message Persistence API: history() method that is not recommended for Python-Asyncio SDK"
updated_at: 2026-11-25T12:28:11.000Z
sdk_name: PubNub Python Asyncio SDK
sdk_version: 10.9.1
description: Not recommended. Reference for the history() method in the PubNub Python-Asyncio SDK. Message Persistence itself is current. New apps use fetch_messages().
lifecycle: deprecated-method
feature_status: current
feature: Message Persistence
replaced_by: "https://www.pubnub.com/docs/sdks/asyncio/api-reference/message-persistence.md"
---

# Message Persistence API: history() method that is not recommended for Python-Asyncio SDK

PubNub Python Asyncio SDK, use the latest version: 10.9.1

Install:

```bash
pip install pubnub==10.9.1
```

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

> **Not recommended.** The Message Persistence feature is current and fully supported. Only the method documented on this page is deprecated. Do not use it in new code. Explain it only to developers who already call it.
>
> Page notice: Message Persistence is a current API. The history() method is an older way to read it. New apps should use fetch_messages().
>
> Current API: https://www.pubnub.com/docs/sdks/asyncio/api-reference/message-persistence.md

This page documents the `history()` method of the PubNub Python-Asyncio SDK. The SDK source does not tag it as deprecated, but its use is not recommended. Message Persistence is a current API, and `history()` is an older way to read it. The method remains for apps that already use it. New apps call [`fetch_messages()`](https://www.pubnub.com/docs/sdks/asyncio/api-reference/message-persistence.md#fetch-history).

## History (not recommended)

:::warning Not recommended
The use of `history()` is discouraged. Use [`fetch_messages()`](https://www.pubnub.com/docs/sdks/asyncio/api-reference/message-persistence.md#fetch-history) instead.
:::

:::note Requires Message Persistence add-on
This method requires that the *Message Persistence* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

`history()` fetches the messages of one channel. These options control which messages it returns and in what order:

* By default, the search starts at the newest end of the timeline, which is `reverse` set to `False`.
* To search from the oldest end of the timeline, set `reverse` to `True`.
* To page through results, provide `start` or `end`.
* To retrieve a slice of the timeline, provide both `start` and `end`.
* To limit the number of messages, use `count`.

### Method(s)

`history()` takes no arguments, so it has no keyword form. Use the builder.

A builder sends its request when you await its `future()`. A request that fails, or fails validation, does not raise an exception. `future()` resolves with a `PubNubAsyncioException` whose `result` is `None` and whose `status` holds the error. Call `is_error()` on the awaited value before you read `result`.

```python
await pubnub.history() \
    .channel(channel: str) \
    .reverse(reverse: bool) \
    .include_timetoken(include_timetoken: bool) \
    .include_meta(include_meta: bool) \
    .start(start: int) \
    .end(end: int) \
    .count(count: int) \
    .future() -> AsyncioEnvelope
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| channel | str | Yes | n/a | ID of the channel to return history messages from. An empty value fails validation with the message `Channel missing`. |
| reverse | bool | Optional | `False` | Whether to traverse the timeline from the oldest message to the newest. |
| include_timetoken | bool | Optional | `False` | Whether each message in the response carries its timetoken. Pass the value, as in `include_timetoken(True)`. |
| include_meta | bool | Optional | `False` | Whether each message in the response carries the metadata that its publisher set at publish time. |
| start | int | Optional | n/a | Timetoken that sets the newer boundary of the query (exclusive). Retrieval begins at this timetoken and moves backward in time. With `end`, `start` must be a higher timetoken than `end`. The service rejects `-1` with an HTTP 400 error. |
| end | int | Optional | n/a | Timetoken that sets the older boundary of the query (inclusive). Retrieval stops at this timetoken. With `start`, `end` must be a lower timetoken than `start`. With `reverse` set to `True`, `end` becomes the newer boundary, so the response holds the older messages. |
| count | int | Optional | `100` | Number of messages to return. The maximum is `100`, and `history()` replaces a larger value or a value below `1` with `100`. |

`history()` always returns the messages sorted from the oldest to the newest, whatever `reverse` is. The `reverse` setting matters when more than `100` messages, or more than `count` if you set it, fall in the time interval. In that case, `reverse` decides which end of the interval the retrieval starts from.

### Sample code

Retrieve the last 100 messages on a channel:

```python
envelope = await pubnub.history() \
    .channel("history_channel_2") \
    .count(100) \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

### Returns

`history()` resolves with an `AsyncioEnvelope` whose `result` is a `PNHistoryResult` and whose `status` is a `PNStatus`.

| Property | Type | Description |
| --- | --- | --- |
| messages | list | The returned messages, oldest first. Each item is a `PNHistoryItemResult`. |
| start_timetoken | int | Timetoken of the oldest returned message. |
| end_timetoken | int | Timetoken of the newest returned message. |

Each `PNHistoryItemResult` has these properties:

| Property | Type | Description |
| --- | --- | --- |
| entry | any | The message payload. |
| timetoken | int | Timetoken of the message. `None` without `include_timetoken`. |
| meta | any | Metadata that the publisher set. `None` without `include_meta` or when the message has none. |
| error | Exception | Decryption error, or `None`. |

### Other examples

#### Retrieve the three oldest messages

Set `reverse` to `True` to traverse the timeline from the oldest message first.

```python
envelope = await pubnub.history() \
    .channel("history_channel_2") \
    .count(3) \
    .reverse(True) \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

#### Retrieve messages newer than a timetoken

Page from the oldest message to the newest, starting at a single point in time (exclusive).

```python
envelope = await pubnub.history() \
    .channel("history_channel_2") \
    .start(tokens[1]) \
    .reverse(True) \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

#### Retrieve messages until a timetoken

Page from the newest message to the oldest, until a specific point in time (inclusive). Leave `reverse` unset, because `reverse` set to `True` makes `end` the newer boundary.

```python
envelope = await pubnub.history() \
    .channel("history_channel_2") \
    .count(100) \
    .end(tokens[2]) \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

#### Page through all messages

Call the function with a valid timetoken, for example one above the newest message.

```python
async def get_all_messages(start_tt):
    envelope = await pubnub.history() \
        .channel("history_paging_channel_2") \
        .count(100) \
        .start(start_tt) \
        .future()
    if envelope.is_error():
        print(f"Error: {envelope.status.error_data}")
        return
    msgs = envelope.result.messages
    start = envelope.result.start_timetoken
    end = envelope.result.end_timetoken
    count = len(msgs)

    if count > 0:
        print("%d" % count)
        print("start %d" % start)
        print("end %d" % end)

    if count == 100:
        await get_all_messages(start)
```

#### Include the timetoken in the response

```python
envelope = await pubnub.history() \
    .channel("history_channel_2") \
    .count(100) \
    .include_timetoken(True) \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

Last updated at: 2026-11-25T12:28:11.000Z
