---
source_url: https://www.pubnub.com/docs/sdks/asyncio/api-reference/publish
title: Publish API for Python-Asyncio SDK
updated_at: 2026-11-25T12:28:11.000Z
sdk_name: PubNub Python Asyncio SDK
sdk_version: 10.9.1
description: "Reference for the PubNub Python-Asyncio SDK publish(), signal(), and fire() methods: parameters, results, errors, and limits."
---

# Publish API 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

The PubNub Python-Asyncio SDK sends a message to one [channel](https://www.pubnub.com/docs/architecture/core-concepts.md#channel) per call with `publish()` and a small payload that PubNub never stores with `signal()`.

All three calls require the publish key of your keyset, which you pass as `publish_key` when you create the client. See [Initialization](https://www.pubnub.com/docs/sdks/asyncio/api-reference/configuration.md#initialization).

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

Each builder method has a keyword argument of the same name.

For delivery guarantees, ordering, and the difference between messages and signals, see [Publishing messages with PubNub](https://www.pubnub.com/docs/pub-sub/publish/overview.md). For payload shapes and metadata in practice, see [Send different message types](https://www.pubnub.com/docs/pub-sub/publish/send-different-message-types.md). To receive what you publish, see [Subscribe](https://www.pubnub.com/docs/sdks/asyncio/api-reference/subscribe.md). To fix a failed request, see [Troubleshooting](https://www.pubnub.com/docs/sdks/asyncio/troubleshooting.md).

## Publish

`publish()` sends a message to one channel through a PubNub client for Python-Asyncio and reports the timetoken that PubNub assigned to the message. PubNub delivers the message to the clients that subscribe to the channel.

Publish-processing latency, the time PubNub takes to accept and acknowledge a publish request, is about 0.5 ms within the same region.

### Publish: Prerequisites and limitations

* A client without a `publish_key` gets an error envelope with the message `Publish key not configured`.
* A client does not need to subscribe to a channel to publish to it.
* Each call publishes to one channel. To reach several channels, call `publish()` once per channel.
* By default, a PubNub client for Python-Asyncio does not retry a failed publish, so your application owns the retry.

### Publish: Security

PubNub SDKs connect over TLS 1.2 by default, except the Lua SDK and the unsupported Twisted SDK, where you set `ssl` to `true`.

To encrypt the message content, configure `crypto_module` during initialization. The SDK then encrypts only `message` and sends `channel` and `meta` unencrypted. See [`crypto_module`](https://www.pubnub.com/docs/sdks/asyncio/api-reference/configuration.md#crypto_module) for the setup and [Data security and encryption](https://www.pubnub.com/docs/security/encryption/overview.md) for background.

### Publish: Message data

A message is the basic unit of data flowing through PubNub, and its payload is any JSON-serializable value. String content in a message payload can include any single-byte or multi-byte UTF-8 character. Pass objects as they are. The SDK serializes `message` and `meta`, so don't call `json.dumps()` first. Avoid special classes and functions.

Metadata values must be JSON-serializable. The SDK sends `meta` only when it is not empty.

### Publish: Size

PubNub supports message sizes **up to 2 MB**. PubNub default message size limit is 32 KiB, which includes the channel name and any metadata. Contact [support](https://support.pubnub.com/) or your account manager to request higher message size limits and help on large message design patterns.

PubNub rejects a larger publish. A POST request fails with HTTP status 413 and a GET request fails with HTTP status 414. For all publish limits, see [API limits](https://www.pubnub.com/docs/architecture/limits.md#publish). To calculate the payload size, use the [message size calculator](https://www.pubnub.com/docs/pub-sub/publish/send-different-message-types.md#publish-a-message).

### Publish: Publish rate

There is no hard publish rate limit for a keyset in good standing. As a best practice, keep publish rates at 10 to 15 messages per second per channel. Faster rates are possible, but a slow subscriber can fall behind the connection's message buffer.

### Publish: Custom message type

You can optionally provide the `custom_message_type` parameter to add your business-specific label or category to the message, for example `text`, `action`, or `poll`.

A custom message type accepted by the PubNub Publish, Signal, and File Sharing APIs must be a case-sensitive alphanumeric string of 3 to 50 characters. Dashes (`-`) and underscores (`_`) are allowed. The value cannot start with a special character or with the reserved prefixes `pn_` or `pn-`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| message | Any | Yes | n/a | The payload to publish. Any JSON-serializable value, such as an object, array, string, or number. A `None` value fails validation with the message `Message missing`. Other falsy values such as `0`, `False`, and `""` are valid. |
| channel | str | Yes | n/a | The ID of the one channel to publish to. The method takes the ID string, not an [SDK channel entity](https://www.pubnub.com/docs/sdks/asyncio/api-reference/subscribe.md#sdk-entities). An empty value fails validation with the message `Channel missing`. |
| should_store | bool | Optional | n/a | Whether PubNub stores the message in [Message Persistence](https://www.pubnub.com/docs/data-storage/message-history/overview.md). `true` stores it and `false` skips storage. PubNub stores the message only when Message Persistence is enabled for the keyset. When omitted, the Message Persistence setting of the keyset applies. |
| meta | Any | Optional | `None` | Metadata that PubNub attaches to the message. Subscribers can use it in [message filters](https://www.pubnub.com/docs/pub-sub/subscribe/filter-received-messages.md). |
| use_post | bool | Optional | `False` | Whether the message travels in the body of an HTTP POST request. `false` puts the message in the URL path of an HTTP GET request. |
| ttl | int | Optional | n/a | The number of hours that Message Persistence keeps the message. When omitted, the retention of the keyset applies. PubNub ignores this value when it does not store the message. The SDK sends `ttl` only when the value is not `0`. A keyset using Unlimited retention ignores any per-message TTL and stores the message indefinitely. |
| custom_message_type | str | Optional | n/a | A business-specific label for the message, for example `text`, `action`, or `poll`. The accepted format is in the Custom message type note for this method. |

### Returns

`publish()` resolves with an `AsyncioEnvelope` whose `result` is a `PNPublishResult` and whose `status` is a `PNStatus`.

#### PNPublishResult

| Property | Type | Description |
| --- | --- | --- |
| timetoken | int | The timetoken that PubNub assigned to the message. PubNub assigns every published message a server-side timetoken: a monotonically increasing 17-digit value precise to 100 nanoseconds (10⁻⁷ s), the number of 100-nanosecond intervals since the Unix epoch. For how to use it, see [Publish response and the timetoken](https://www.pubnub.com/docs/pub-sub/publish/overview.md#publish-response-and-the-timetoken). |

### Publish errors

A failed `publish()` does not raise. The awaited value is a `PubNubAsyncioException` with `result` set to `None`. Call `is_error()` on it, and read the cause from its `status`.

The SDK checks the inputs before it sends any request, and a failed check is reported the same way.

| Condition | Result |
| --- | --- |
| `channel` is omitted or empty | Error status with the message `Channel missing`. |
| `message` is `None` or omitted | Error status with the message `Message missing`. |
| `publish_key` was not set at initialization | Error status with the message `Publish key not configured`. |
| `subscribe_key` was not set at initialization | Error status with the message `Subscribe key not configured`. |
| `message` or `meta` is not JSON-serializable | Error status with the message `Trying to publish not JSON serializable object`. |
| `custom_message_type` is not in the accepted format | The SDK does not check the format, so PubNub rejects the request. Read the status for the reason. |
| The token or `auth_key` has no write permission on the channel | Error status for HTTP status 403, with category `PNAccessDeniedCategory`. See [Access Manager](https://www.pubnub.com/docs/security/access-control/overview.md). |
| The message exceeds the size limit | Error status for HTTP status 413 over POST or 414 over GET. |
| The network is unreachable | Error status with the message `Connection Error`. |

### Examples for Publish

#### Syntax

```python
await pubnub.publish(
    message: Any,
    channel: str,
    should_store: bool,
    meta: Any,
    use_post: bool,
    ttl: int,
    custom_message_type: str
).future() -> AsyncioEnvelope
```

#### Publish a message to a channel (Builder Pattern)

```python
envelope = await pubnub.publish() \
    .channel("my_channel") \
    .message({
        'name': 'Alex',
        'online': True
    }) \
    .custom_message_type("text-message") \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

#### Publish a message to a channel (Named Arguments)

```python
envelope = await pubnub.publish(
    channel="my_channel",
    message={
        'name': 'Sam',
        'online': False
    },
    custom_message_type="text-message",
    meta={'origin': 'docs'}
).future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

#### Publish with metadata

Publish with `meta` and check the status of the envelope.

```python
envelope = await pubnub.publish()\
    .channel("my_channel")\
    .message(["hello", "there"])\
    .meta({'name': 'Alex'})\
    .future()
# handle publish result, status always present, result if successful
# envelope.status.is_error() to see if error happened
```

#### Store the message and publish with POST

Set `should_store` to choose whether Message Persistence keeps each message, and send the body with `use_post`.

```python
stored = await pubnub.publish() \
    .channel("my_channel") \
    .message({'kept': True}) \
    .should_store(True) \
    .use_post(True) \
    .future()
if stored.is_error():
    print(f"Error: {stored.status.error_data}")

not_stored = await pubnub.publish() \
    .channel("my_channel") \
    .message({'kept': False}) \
    .should_store(False) \
    .use_post(True) \
    .future()
if not_stored.is_error():
    print(f"Error: {not_stored.status.error_data}")
```

## Signal

`signal()` sends a signal to the clients that subscribe to one channel, using a PubNub client for Python-Asyncio.

PubNub never stores signals in Message Persistence, regardless of keyset settings. Signal payloads are limited to 64 bytes. A signal cannot trigger mobile push notifications. A signal does not support `meta`, `should_store`, `ttl`, or `use_post`. The SDK does not encrypt the `message` of a signal, even when a `crypto_module` is configured.

PubNub rejects a payload over the limit. The error status carries the HTTP status code and the reason.

`signal()` fails validation when `channel` is missing or empty, or when `publish_key` or `subscribe_key` is missing. The SDK does not check `message`. See [Publish errors](#publish-errors).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| message | Any | Yes | n/a | The payload to send. Any JSON-serializable value. |
| channel | str | Yes | n/a | The ID of the one channel to send the signal to. The method takes the ID string, not an [SDK channel entity](https://www.pubnub.com/docs/sdks/asyncio/api-reference/subscribe.md#sdk-entities). An empty value fails validation with the message `Channel missing`. |
| custom_message_type | str | Optional | n/a | A business-specific label for the signal, for example `text`, `action`, or `poll`. The accepted format is the same as for [`publish()`](#publish), described in the Custom message type note under Publish. |

### Returns

`signal()` resolves with an `AsyncioEnvelope` whose `result` is a `PNSignalResult` and whose `status` is a `PNStatus`.

#### PNSignalResult

| Property | Type | Description |
| --- | --- | --- |
| timetoken | str | The timetoken that PubNub assigned to the signal. |

### Examples for Signal

#### Syntax

```python
await pubnub.signal(
    message: Any,
    channel: str,
    custom_message_type: str
).future() -> AsyncioEnvelope
```

#### Signal a message to a channel

```python
envelope = await pubnub.signal() \
    .channel("my_channel") \
    .message("typing_on") \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

## Fire

`fire()` sends a message to Functions event handlers and Illuminate through a PubNub client for Python-Asyncio, bypassing subscribers and storage.

The message goes straight to the handlers registered on the target channel and triggers them. Each handler can read the request body. PubNub does not replicate a fired message to subscribers and does not store it in Message Persistence.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| message | Any | Yes | n/a | The payload to publish. Any JSON-serializable value, such as an object, array, string, or number. A `None` value fails validation with the message `Message missing`. |
| channel | str | Yes | n/a | The ID of the one channel to fire to. The method takes the ID string, not an [SDK channel entity](https://www.pubnub.com/docs/sdks/asyncio/api-reference/subscribe.md#sdk-entities). An empty value fails validation with the message `Channel missing`. |
| meta | Any | Optional | `None` | Metadata that PubNub attaches to the message. Subscribers can use it in [message filters](https://www.pubnub.com/docs/pub-sub/subscribe/filter-received-messages.md). |
| use_post | bool | Optional | `False` | Whether the message travels in the body of an HTTP POST request. `false` puts the message in the URL path of an HTTP GET request. |

### Returns

`fire()` resolves with an `AsyncioEnvelope` whose `result` is a `PNFireResult` and whose `status` is a `PNStatus`.

#### PNFireResult

| Property | Type | Description |
| --- | --- | --- |
| timetoken | int | The timetoken that PubNub assigned to the fired message. |

### Fire errors

`fire()` fails validation on the same inputs as `publish()`: a missing `channel`, a `None` `message`, or a missing `publish_key` or `subscribe_key`. See [Publish errors](#publish-errors).

### Examples for Fire

#### Syntax

```python
await pubnub.fire(
    message: Any,
    channel: str,
    meta: Any,
    use_post: bool
).future() -> AsyncioEnvelope
```

#### Fire a message to a channel

```python
envelope = await pubnub.fire() \
    .channel("my_channel") \
    .message({'command': 'refresh'}) \
    .future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
```

#### Fire a message with POST

```python
envelope = await pubnub.fire().channel('my_channel').message('hello there').use_post(True).future()
if envelope.is_error():
    print(f"Error: {envelope.status.error_data}")
else:
    print('fire timetoken: %d' % envelope.result.timetoken)
```

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