> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-vector.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Publish

<Info>
  You can run the async code by importing `Client` from `upstash_qstash.asyncio`
  and awaiting the methods.
</Info>

#### Publish to a URL with a 3 second delay and headers/body

```python
from upstash_qstash import Client

client = Client("<QSTASH_TOKEN>")
res = client.publish_json({
  "url": "https://my-api...",
  "body": { "hello": "world" },
  "headers": { "test-header": "test-value" },
  "delay": 3
})

print(res["messageId"])
```

#### Publish to a topic with a 3 second delay and headers/body

You can make a topic on the QStash console or using the [topics API](/qstash/sdks/py/examples/topics)

```python
from upstash_qstash import Client

client = Client("<QSTASH_TOKEN>")
res = client.publish_json({
  "topic": "mytopic",
  "body": { "hello": "world" },
  "headers": { "test-header": "test-value" },
  "delay": 3
})

# When publishing to a topic, the response is an array of messages for each URL in the topic
print(res[0]["messageId"])
```

#### Publish a method with a callback URL

[Callbacks](/qstash/features/callbacks) are useful for long running functions. Here, QStash will return the response
of the publish request to the callback URL.

We also change the `method` to `GET` in this use case so QStash will make a `GET` request to the `url`. The default
is `POST`.

```python
from upstash_qstash import Client

client = Client("<QSTASH_TOKEN>")
client.publish_json({
  "url": "https://my-api...",
  "body": { "hello": "world" },
  "callback": "https://my-callback...",
  "failure_callback": "https://my-failure-callback...",
  "method": "GET"
})
```

#### Configure the number of retries

The max number of retries is based on your [QStash plan](https://upstash.com/pricing/qstash)

```python
from upstash_qstash import Client

client = Client("<QSTASH_TOKEN>")
client.publish_json({
  "url": "https://my-api...",
  "body": { "hello": "world" },
  "retries": 1
})
```

#### Publish HTML content instead of JSON

```python
from upstash_qstash import Client

client = Client("<QSTASH_TOKEN>")
client.publish({
  "url": "https://my-api...",
  "body": "<html><body><h1>Hello World</h1></body></html>",
  "headers": {
    "Content-Type": "text/html"
  }
})
```

#### Publish a message with [content-based-deduplication](/qstash/features/deduplication)

```python
from upstash_qstash import Client

client = Client("<QSTASH_TOKEN>")
client.publish_json({
  "url": "https://my-api...",
  "body": { "hello": "world" },
  "content_based_deduplication": True
})
```
