Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Install with `pip` from pypi.org:

```bash
pip install pgmq-py
pip install pgmq
```

To use the async version, install with the optional dependencies:

```bash
pip install pgmq-py[async]
pip install pgmq[async]
```

Dependencies:
Expand Down Expand Up @@ -41,7 +41,7 @@ export PG_DATABASE=test_db
Initialize a connection to Postgres using environment variables:

```python
from pgmq_py import PGMQueue, Message
from pgmq import PGMQueue, Message

queue = PGMQueue()
```
Expand All @@ -51,7 +51,7 @@ queue = PGMQueue()
Initialization for the async version requires an explicit call of the initializer:

```python
from pgmq_py.async_queue import PGMQueue
from pgmq.async_queue import PGMQueue

async def main():
queue = PGMQueue()
Expand All @@ -63,7 +63,7 @@ Then, the interface is exactly the same as the sync version.
### Initialize a connection to Postgres without environment variables

```python
from pgmq_py import PGMQueue, Message
from pgmq import PGMQueue, Message

queue = PGMQueue(
host="0.0.0.0",
Expand Down Expand Up @@ -260,13 +260,13 @@ queue = PGMQueue(

# Using Transactions

To perform multiple operations within a single transaction, use the `@transaction` decorator from the `pgmq_py.decorators` module.
To perform multiple operations within a single transaction, use the `@transaction` decorator from the `pgmq.decorators` module.
This ensures that all operations within the function are executed within the same transaction and are either committed together or rolled back if an error occurs.

First, import the transaction decorator:

```python
from pgmq_py.decorators import transaction
from pgmq.decorators import transaction
```

### Example: Transactional Operation
Expand Down
2 changes: 1 addition & 1 deletion benches/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional
import pandas as pd
from sqlalchemy import create_engine, text
from pgmq_py import PGMQueue
from pgmq import PGMQueue
from urllib.parse import urlparse
import typer
from benches.ops import consume, produce, queue_depth
Expand Down
2 changes: 1 addition & 1 deletion benches/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from pgmq_py import PGMQueue
from pgmq import PGMQueue
from locust import task, User


Expand Down
3 changes: 1 addition & 2 deletions benches/ops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import logging
import multiprocessing
import os
import time
import psycopg
Expand Down Expand Up @@ -183,7 +182,7 @@ def consume(
def queue_depth(
queue_name: str,
connection_info: dict,
kill_flag: multiprocessing.Value,
kill_flag,
duration_seconds: int,
):
username = connection_info["username"]
Expand Down
2 changes: 1 addition & 1 deletion benches/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy import create_engine, text
import numpy as np
from benches.log import write_event_log
from pgmq_py import PGMQueue
from pgmq import PGMQueue


def stack_events(
Expand Down
4 changes: 2 additions & 2 deletions example/example_app_async.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from pgmq_py.async_queue import PGMQueue
from pgmq_py.decorators import async_transaction as transaction
from pgmq.async_queue import PGMQueue
from pgmq.decorators import async_transaction as transaction


async def main():
Expand Down
4 changes: 2 additions & 2 deletions example/example_app_sync.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pgmq_py.queue import PGMQueue
from pgmq_py.decorators import transaction
from pgmq.queue import PGMQueue
from pgmq.decorators import transaction

queue = PGMQueue(
host="localhost",
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pgmq-py"
version = "0.1.0"
name = "pgmq"
version = "1.0.0"
description = "Python client for the PGMQ Postgres extension."
readme = "README.md"
license = "Apache-2.0"
Expand Down
4 changes: 4 additions & 0 deletions src/pgmq/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pgmq.queue import Message, PGMQueue # type: ignore
from pgmq.decorators import transaction, async_transaction

__all__ = ["Message", "PGMQueue", "transaction", "async_transaction"]
4 changes: 2 additions & 2 deletions src/pgmq_py/async_queue.py → src/pgmq/async_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from orjson import dumps, loads

from pgmq_py.messages import Message, QueueMetrics
from pgmq_py.decorators import async_transaction as transaction
from pgmq.messages import Message, QueueMetrics
from pgmq.decorators import async_transaction as transaction


@dataclass
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/pgmq_py/queue.py → src/pgmq/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from psycopg.types.json import Jsonb
from psycopg_pool import ConnectionPool
import os
from pgmq_py.messages import Message, QueueMetrics
from pgmq_py.decorators import transaction
from pgmq.messages import Message, QueueMetrics
from pgmq.decorators import transaction
import logging
import datetime

Expand Down
4 changes: 0 additions & 4 deletions src/pgmq_py/__init__.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/test_async_integration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest
import time
from pgmq_py.messages import Message
from pgmq_py.async_queue import PGMQueue
from pgmq_py.decorators import async_transaction as transaction
from pgmq.messages import Message
from pgmq.async_queue import PGMQueue
from pgmq.decorators import async_transaction as transaction
from datetime import datetime, timezone, timedelta

# Function to load environment variables
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import time
from pgmq_py import Message, PGMQueue, transaction
from pgmq import Message, PGMQueue, transaction

from datetime import datetime, timezone, timedelta

Expand Down Expand Up @@ -60,7 +60,7 @@ def test_send_message_with_delay(self):
msg_id = self.queue.send(self.test_queue, self.test_message, delay=5)
message = self.queue.read(self.test_queue, vt=20)
self.assertIsNone(message, "Message should not be visible yet")
time.sleep(5)
time.sleep(6)
message: Message = self.queue.read(self.test_queue, vt=20)
self.assertIsNotNone(message, "Message should be visible after delay")
self.assertEqual(message.message, self.test_message)
Expand Down
Loading