Skip to content

Commit

Permalink
Merge pull request #27 from upstash/rename-package
Browse files Browse the repository at this point in the history
Rename package to qstash
  • Loading branch information
CahidArda authored Jul 19, 2024
2 parents 938d40f + 7958991 commit 098657d
Show file tree
Hide file tree
Showing 50 changed files with 448 additions and 446 deletions.
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
### Install

```shell
pip install qstash-python
pip install qstash
```

### Usage
Expand All @@ -23,11 +23,11 @@ You can get your QStash token from the [Upstash Console](https://console.upstash
#### Publish a JSON message

```python
from upstash_qstash import QStash
from qstash import QStash

qstash = QStash("<QSTASH_TOKEN>")
client = QStash("<QSTASH_TOKEN>")

res = qstash.message.publish_json(
res = client.message.publish_json(
url="https://example.com",
body={"hello": "world"},
headers={
Expand All @@ -41,11 +41,11 @@ print(res.message_id)
#### [Create a scheduled message](https://upstash.com/docs/qstash/features/schedules)

```python
from upstash_qstash import QStash
from qstash import QStash

qstash = QStash("<QSTASH_TOKEN>")
client = QStash("<QSTASH_TOKEN>")

schedule_id = qstash.schedule.create(
schedule_id = client.schedule.create(
destination="https://example.com",
cron="*/5 * * * *",
)
Expand All @@ -56,7 +56,7 @@ print(schedule_id)
#### [Receiving messages](https://upstash.com/docs/qstash/howto/receiving)

```python
from upstash_qstash import Receiver
from qstash import Receiver

# Keys available from the QStash console
receiver = Receiver(
Expand All @@ -78,12 +78,12 @@ receiver.verify(
#### Create Chat Completions

```python
from upstash_qstash import QStash
from upstash_qstash.chat import upstash
from qstash import QStash
from qstash.chat import upstash

qstash = QStash("<QSTASH_TOKEN>")
client = QStash("<QSTASH_TOKEN>")

res = qstash.chat.create(
res = client.chat.create(
model="meta-llama/Meta-Llama-3-8B-Instruct",
provider=upstash(),
messages=[
Expand All @@ -100,12 +100,12 @@ print(res.choices[0].message.content)
#### Create Chat Completions Using Custom Providers

```python
from upstash_qstash import QStash
from upstash_qstash.chat import openai
from qstash import QStash
from qstash.chat import openai

qstash = QStash("<QSTASH_TOKEN>")
client = QStash("<QSTASH_TOKEN>")

res = qstash.chat.create(
res = client.chat.create(
model="gpt-3.5-turbo",
provider=openai("<OPENAI_API_KEY>"),
messages=[
Expand All @@ -122,12 +122,12 @@ print(res.choices[0].message.content)
#### Publish a JSON message to LLM

```python
from upstash_qstash import QStash
from upstash_qstash.chat import upstash
from qstash import QStash
from qstash.chat import upstash

qstash = QStash("<QSTASH_TOKEN>")
client = QStash("<QSTASH_TOKEN>")

res = qstash.message.publish_json(
res = client.message.publish_json(
api={"name": "llm", "provider": upstash()},
body={
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
Expand All @@ -147,12 +147,12 @@ print(res.message_id)
#### Publish a JSON message to LLM Using Custom Providers

```python
from upstash_qstash import QStash
from upstash_qstash.chat import openai
from qstash import QStash
from qstash.chat import openai

qstash = QStash("<QSTASH_TOKEN>")
client = QStash("<QSTASH_TOKEN>")

res = qstash.message.publish_json(
res = client.message.publish_json(
api={"name": "llm", "provider": openai("<OPENAI_API_KEY>")},
body={
"model": "gpt-3.5-turbo",
Expand All @@ -172,7 +172,7 @@ print(res.message_id)
#### Additional configuration

```python
from upstash_qstash import QStash
from qstash import QStash

# Create a client with a custom retry configuration. This is
# for sending messages to QStash, not for sending messages to
Expand All @@ -182,16 +182,16 @@ from upstash_qstash import QStash
# "retries": 5,
# "backoff": lambda retry_count: math.exp(retry_count) * 50,
# }
qstash = QStash(
client = QStash(
token="<QSTASH_TOKEN>",
retry={
"retries": 1,
"backoff": lambda retry_count: (2 ** retry_count) * 20,
},
)

# Publish to Topic
qstash.message.publish_json(
# Publish to URL
client.message.publish_json(
url="https://example.com",
body={"key": "value"},
# Retry sending message to API 3 times
Expand Down
6 changes: 3 additions & 3 deletions examples/async_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import asyncio

from upstash_qstash import AsyncQStash
from qstash import AsyncQStash


async def main():
qstash = AsyncQStash(
client = AsyncQStash(
token="<QSTASH-TOKEN>",
)

res = await qstash.message.publish_json(
res = await client.message.publish_json(
url="https://example.com",
body={"hello": "world"},
headers={
Expand Down
6 changes: 3 additions & 3 deletions examples/basic_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Publishes a JSON message with a 3s delay to a URL using QStash.
"""

from upstash_qstash import QStash
from qstash import QStash


def main():
qstash = QStash(
client = QStash(
token="<QSTASH-TOKEN>",
)

res = qstash.message.publish_json(
res = client.message.publish_json(
url="https://example.com",
body={"hello": "world"},
headers={
Expand Down
8 changes: 4 additions & 4 deletions examples/basic_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Create a schedule that publishes a message every minute.
"""

from upstash_qstash import QStash
from qstash import QStash


def main():
qstash = QStash(
client = QStash(
token="<QSTASH-TOKEN>",
)

schedule_id = qstash.schedule.create_json(
schedule_id = client.schedule.create_json(
cron="* * * * *",
destination="https://example..com",
body={"hello": "world"},
Expand All @@ -20,7 +20,7 @@ def main():
print(schedule_id)

# You can also get a schedule by ID
schedule = qstash.schedule.get(schedule_id)
schedule = client.schedule.get(schedule_id)
print(schedule.cron)


Expand Down
6 changes: 3 additions & 3 deletions examples/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
to wait for the response in a serverless function.
"""

from upstash_qstash import QStash
from qstash import QStash


def main():
qstash = QStash(
client = QStash(
token="<QSTASH-TOKEN>",
)

qstash.message.publish_json(
client.message.publish_json(
url="https://expensive.com",
callback="https://example-cb.com",
# We want to send a GET request to https://expensive.com and have the response
Expand Down
8 changes: 4 additions & 4 deletions examples/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
at once, or streaming chunk by chunk.
"""

from upstash_qstash import QStash
from qstash import QStash


def main():
qstash = QStash(
client = QStash(
token="<QSTASH-TOKEN>",
)

res = qstash.chat.create(
res = client.chat.create(
messages=[{"role": "user", "content": "How are you?"}],
model="meta-llama/Meta-Llama-3-8B-Instruct",
)

# Get the response at once
print(res.choices[0].message.content)

stream_res = qstash.chat.create(
stream_res = client.chat.create(
messages=[{"role": "user", "content": "How are you again?"}],
model="meta-llama/Meta-Llama-3-8B-Instruct",
stream=True,
Expand Down
8 changes: 4 additions & 4 deletions examples/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
to wait for the response in a serverless function.
"""

from upstash_qstash import QStash
from upstash_qstash.chat import upstash
from qstash import QStash
from qstash.chat import upstash


def main():
qstash = QStash(
client = QStash(
token="<QSTASH-TOKEN>",
)

qstash.message.publish_json(
client.message.publish_json(
api={"name": "llm", "provider": upstash()},
body={
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tool.poetry]
name = "qstash-python"
name = "qstash"
version = "2.0.0"
description = "Python SDK for Upstash QStash"
license = "MIT"
authors = ["Upstash <[email protected]>"]
maintainers = ["Upstash <[email protected]>"]
readme = "README.md"
repository = "https://github.com/upstash/qstash-python"
repository = "https://github.com/upstash/qstash-py"
keywords = ["QStash", "Upstash QStash", "Serverless Queue"]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand All @@ -27,7 +27,7 @@ classifiers = [
"Topic :: Software Development :: Libraries",
]

packages = [{ include = "upstash_qstash" }]
packages = [{ include = "qstash" }]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
6 changes: 6 additions & 0 deletions qstash/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from qstash.asyncio.client import AsyncQStash
from qstash.client import QStash
from qstash.receiver import Receiver

__version__ = "2.0.0"
__all__ = ["QStash", "AsyncQStash", "Receiver"]
File renamed without changes.
4 changes: 2 additions & 2 deletions upstash_qstash/asyncio/chat.py → qstash/asyncio/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import httpx

from upstash_qstash.asyncio.http import AsyncHttpClient
from upstash_qstash.chat import (
from qstash.asyncio.http import AsyncHttpClient
from qstash.chat import (
ChatCompletion,
ChatCompletionChunk,
ChatCompletionMessage,
Expand Down
20 changes: 10 additions & 10 deletions upstash_qstash/asyncio/qstash.py → qstash/asyncio/client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from typing import Literal, Optional, Union

from upstash_qstash.asyncio.chat import AsyncChatApi
from upstash_qstash.asyncio.dlq import AsyncDlqApi
from upstash_qstash.asyncio.event import AsyncEventApi
from upstash_qstash.asyncio.http import AsyncHttpClient
from upstash_qstash.asyncio.message import AsyncMessageApi
from upstash_qstash.asyncio.queue import AsyncQueueApi
from upstash_qstash.asyncio.schedule import AsyncScheduleApi
from upstash_qstash.asyncio.signing_key import AsyncSigningKeyApi
from upstash_qstash.asyncio.url_group import AsyncUrlGroupApi
from upstash_qstash.http import RetryConfig
from qstash.asyncio.chat import AsyncChatApi
from qstash.asyncio.dlq import AsyncDlqApi
from qstash.asyncio.event import AsyncEventApi
from qstash.asyncio.http import AsyncHttpClient
from qstash.asyncio.message import AsyncMessageApi
from qstash.asyncio.queue import AsyncQueueApi
from qstash.asyncio.schedule import AsyncScheduleApi
from qstash.asyncio.signing_key import AsyncSigningKeyApi
from qstash.asyncio.url_group import AsyncUrlGroupApi
from qstash.http import RetryConfig


class AsyncQStash:
Expand Down
4 changes: 2 additions & 2 deletions upstash_qstash/asyncio/dlq.py → qstash/asyncio/dlq.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from typing import List, Optional

from upstash_qstash.asyncio.http import AsyncHttpClient
from upstash_qstash.dlq import (
from qstash.asyncio.http import AsyncHttpClient
from qstash.dlq import (
DlqMessage,
ListDlqMessagesResponse,
parse_dlq_message_response,
Expand Down
5 changes: 3 additions & 2 deletions upstash_qstash/asyncio/event.py → qstash/asyncio/event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
from upstash_qstash.asyncio.http import AsyncHttpClient
from upstash_qstash.event import (

from qstash.asyncio.http import AsyncHttpClient
from qstash.event import (
EventFilter,
ListEventsResponse,
parse_events_response,
Expand Down
2 changes: 1 addition & 1 deletion upstash_qstash/asyncio/http.py → qstash/asyncio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import httpx

from upstash_qstash.http import (
from qstash.http import (
BASE_URL,
DEFAULT_RETRY,
NO_RETRY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
from typing import Any, Dict, List, Optional, Union

from upstash_qstash.asyncio.http import AsyncHttpClient
from upstash_qstash.http import HttpMethod
from upstash_qstash.message import (
from qstash.asyncio.http import AsyncHttpClient
from qstash.http import HttpMethod
from qstash.message import (
ApiT,
BatchJsonRequest,
BatchRequest,
Expand Down
4 changes: 2 additions & 2 deletions upstash_qstash/asyncio/queue.py → qstash/asyncio/queue.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List

from upstash_qstash.asyncio.http import AsyncHttpClient
from upstash_qstash.queue import Queue, parse_queue_response, prepare_upsert_body
from qstash.asyncio.http import AsyncHttpClient
from qstash.queue import Queue, parse_queue_response, prepare_upsert_body


class AsyncQueueApi:
Expand Down
Loading

0 comments on commit 098657d

Please sign in to comment.