pgmq-sqlalchemy


Namepgmq-sqlalchemy JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryMore flexible PGMQ Postgres extension Python client that using sqlalchemy ORM, supporting both async and sync engines, sessionmakers or built from dsn.
upload_time2024-08-03 16:11:30
maintainerNone
docs_urlNone
authorjason810496
requires_python<4.0,>=3.9
licenseMIT
keywords pgmq pgmq sqlalchemy sqlalchemy tembo_pgmq_python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![PyPI - Version](https://img.shields.io/pypi/v/pgmq-sqlalchemy)
[![PyPI - License](https://img.shields.io/pypi/l/pgmq-sqlalchemy.svg)](https://github.com/jason810496/pgmq-sqlalchemy/blob/main/LICENSE)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pgmq-sqlalchemy.svg)](https://pypi.python.org/pypi/pgmq-sqlalchemy)
[![codecov](https://codecov.io/gh/jason810496/pgmq-sqlalchemy/graph/badge.svg?token=C5ZVZCW7TE)](https://codecov.io/gh/jason810496/pgmq-sqlalchemy)
[![Documentation Status](https://readthedocs.org/projects/pgmq-sqlalchemy/badge/?version=latest)](https://pgmq-sqlalchemy.readthedocs.io/en/latest/?badge=latest)


# pgmq-sqlalchemy

More flexible [PGMQ Postgres extension](https://github.com/tembo-io/pgmq) Python client that using **sqlalchemy ORM**, supporting both **async** and **sync** `engines`, `sessionmakers` or built from `dsn`.

## Table of Contents

* [pgmq-sqlalchemy](#pgmq-sqlalchemy)
   * [Features](#features)
   * [Installation](#installation)
   * [Getting Started](#getting-started)
      * [Postgres Setup](#postgres-setup)
      * [Usage](#usage)
   * [Issue/ Contributing / Development](#issue-contributing--development)
   * [TODO](#todo)


## Features

- Supports **async** and **sync** `engines` and `sessionmakers`, or built from `dsn`.
- **Automatically** creates `pgmq` (or `pg_partman`) extension on the database if not exists.
- Supports **all postgres DBAPIs supported by sqlalchemy**.
    > e.g. `psycopg`, `psycopg2`, `asyncpg` .. <br>
    > See [SQLAlchemy Postgresql Dialects](https://docs.sqlalhttps://docs.sqlalchemy.org/en/20/dialects/postgresql.html)

## Installation

Install with pip:

```bash
pip install pgmq-sqlalchemy
```

Install with additional DBAPIs packages:

```bash
pip install "pgmq-sqlalchemy[asyncpg]"
pip install "pgmq-sqlalchemy[psycopg2-binary]"
# pip install "pgmq-sqlalchemy[postgres-python-driver]"
```

## Getting Started

### Postgres Setup

Prerequisites: **Postgres** with **PGMQ** extension installed. <br>
For quick setup: 
```bash
docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 quay.io/tembo/pg16-pgmq:latest
```
> For more information, see [PGMQ](https://github.com/tembo-io/pgmq)

### Usage

> [!NOTE]  
> Check [pgmq-sqlalchemy Document](https://pgmq-sqlalchemy.readthedocs.io/en/latest/) for more examples and detailed usage.


For `dispatcher.py`:
```python
from typing import List
from pgmq_sqlalchemy import PGMQueue

postgres_dsn = 'postgresql://postgres:postgres@localhost:5432/postgres'

pgmq = PGMQueue(dsn=postgres_dsn)
pgmq.create_queue('my_queue')

msg = {'key': 'value', 'key2': 'value2'}
msg_id:int = pgmq.send('my_queue', msg)

# could also send a list of messages
msg_ids:List[int] = pgmq.send_batch('my_queue', [msg, msg])
```

For `consumer.py`:
```python
from pgmq_sqlalchemy import PGMQueue
from pgmq_sqlalchemy.schema import Message

postgres_dsn = 'postgresql://postgres:postgres@localhost:5432/postgres'

pgmq = PGMQueue(dsn=postgres_dsn)

# read a single message
msg:Message = pgmq.read('my_queue')

# read a batch of messages
msgs:List[Message] = pgmq.read_batch('my_queue', 10)
```

For `monitor.py`:
```python
from pgmq_sqlalchemy import PGMQueue
from pgmq_sqlalchemy.schema import QueueMetrics

postgres_dsn = 'postgresql://postgres:postgres@localhost:5432/postgres'

pgmq = PGMQueue(dsn=postgres_dsn)

# get queue metrics
metrics:QueueMetrics = pgmq.metrics('my_queue')
print(metrics.queue_length)
print(metrics.total_messages)
```

## Issue/ Contributing / Development 

Welcome to open an issue or pull request ! <br>
See [`Development` on Online Document](https://pgmq-sqlalchemy.readthedocs.io/en/latest/) or [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information.

## TODO 

- [ ] Add **time-based** partition option and validation to `create_partitioned_queue` method.
- [ ] Read(single/batch) Archive Table ( `read_archive` method )
- [ ] Detach Archive Table ( `detach_archive` method )
- [ ] Add `set_vt` utils method.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pgmq-sqlalchemy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "pgmq, PGMQ, sqlalchemy, SQLAlchemy, tembo_pgmq_python",
    "author": "jason810496",
    "author_email": "810496@email.wlsh.tyc.edu.tw",
    "download_url": "https://files.pythonhosted.org/packages/ef/b3/7dcc4e06d12105082c7f3ec0390ce70c3c1121aa0d7fa33798b14ed46826/pgmq_sqlalchemy-0.1.2.tar.gz",
    "platform": null,
    "description": "[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n![PyPI - Version](https://img.shields.io/pypi/v/pgmq-sqlalchemy)\n[![PyPI - License](https://img.shields.io/pypi/l/pgmq-sqlalchemy.svg)](https://github.com/jason810496/pgmq-sqlalchemy/blob/main/LICENSE)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pgmq-sqlalchemy.svg)](https://pypi.python.org/pypi/pgmq-sqlalchemy)\n[![codecov](https://codecov.io/gh/jason810496/pgmq-sqlalchemy/graph/badge.svg?token=C5ZVZCW7TE)](https://codecov.io/gh/jason810496/pgmq-sqlalchemy)\n[![Documentation Status](https://readthedocs.org/projects/pgmq-sqlalchemy/badge/?version=latest)](https://pgmq-sqlalchemy.readthedocs.io/en/latest/?badge=latest)\n\n\n# pgmq-sqlalchemy\n\nMore flexible [PGMQ Postgres extension](https://github.com/tembo-io/pgmq) Python client that using **sqlalchemy ORM**, supporting both **async** and **sync** `engines`, `sessionmakers` or built from `dsn`.\n\n## Table of Contents\n\n* [pgmq-sqlalchemy](#pgmq-sqlalchemy)\n   * [Features](#features)\n   * [Installation](#installation)\n   * [Getting Started](#getting-started)\n      * [Postgres Setup](#postgres-setup)\n      * [Usage](#usage)\n   * [Issue/ Contributing / Development](#issue-contributing--development)\n   * [TODO](#todo)\n\n\n## Features\n\n- Supports **async** and **sync** `engines` and `sessionmakers`, or built from `dsn`.\n- **Automatically** creates `pgmq` (or `pg_partman`) extension on the database if not exists.\n- Supports **all postgres DBAPIs supported by sqlalchemy**.\n    > e.g. `psycopg`, `psycopg2`, `asyncpg` .. <br>\n    > See [SQLAlchemy Postgresql Dialects](https://docs.sqlalhttps://docs.sqlalchemy.org/en/20/dialects/postgresql.html)\n\n## Installation\n\nInstall with pip:\n\n```bash\npip install pgmq-sqlalchemy\n```\n\nInstall with additional DBAPIs packages:\n\n```bash\npip install \"pgmq-sqlalchemy[asyncpg]\"\npip install \"pgmq-sqlalchemy[psycopg2-binary]\"\n# pip install \"pgmq-sqlalchemy[postgres-python-driver]\"\n```\n\n## Getting Started\n\n### Postgres Setup\n\nPrerequisites: **Postgres** with **PGMQ** extension installed. <br>\nFor quick setup: \n```bash\ndocker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 quay.io/tembo/pg16-pgmq:latest\n```\n> For more information, see [PGMQ](https://github.com/tembo-io/pgmq)\n\n### Usage\n\n> [!NOTE]  \n> Check [pgmq-sqlalchemy Document](https://pgmq-sqlalchemy.readthedocs.io/en/latest/) for more examples and detailed usage.\n\n\nFor `dispatcher.py`:\n```python\nfrom typing import List\nfrom pgmq_sqlalchemy import PGMQueue\n\npostgres_dsn = 'postgresql://postgres:postgres@localhost:5432/postgres'\n\npgmq = PGMQueue(dsn=postgres_dsn)\npgmq.create_queue('my_queue')\n\nmsg = {'key': 'value', 'key2': 'value2'}\nmsg_id:int = pgmq.send('my_queue', msg)\n\n# could also send a list of messages\nmsg_ids:List[int] = pgmq.send_batch('my_queue', [msg, msg])\n```\n\nFor `consumer.py`:\n```python\nfrom pgmq_sqlalchemy import PGMQueue\nfrom pgmq_sqlalchemy.schema import Message\n\npostgres_dsn = 'postgresql://postgres:postgres@localhost:5432/postgres'\n\npgmq = PGMQueue(dsn=postgres_dsn)\n\n# read a single message\nmsg:Message = pgmq.read('my_queue')\n\n# read a batch of messages\nmsgs:List[Message] = pgmq.read_batch('my_queue', 10)\n```\n\nFor `monitor.py`:\n```python\nfrom pgmq_sqlalchemy import PGMQueue\nfrom pgmq_sqlalchemy.schema import QueueMetrics\n\npostgres_dsn = 'postgresql://postgres:postgres@localhost:5432/postgres'\n\npgmq = PGMQueue(dsn=postgres_dsn)\n\n# get queue metrics\nmetrics:QueueMetrics = pgmq.metrics('my_queue')\nprint(metrics.queue_length)\nprint(metrics.total_messages)\n```\n\n## Issue/ Contributing / Development \n\nWelcome to open an issue or pull request ! <br>\nSee [`Development` on Online Document](https://pgmq-sqlalchemy.readthedocs.io/en/latest/) or [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information.\n\n## TODO \n\n- [ ] Add **time-based** partition option and validation to `create_partitioned_queue` method.\n- [ ] Read(single/batch) Archive Table ( `read_archive` method )\n- [ ] Detach Archive Table ( `detach_archive` method )\n- [ ] Add `set_vt` utils method.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "More flexible PGMQ Postgres extension Python client that using sqlalchemy ORM, supporting both async and sync engines, sessionmakers or built from dsn.",
    "version": "0.1.2",
    "project_urls": {
        "Documentation": "https://pgmq-sqlalchemy.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/jason810496/pgmq-sqlalchemy",
        "Repository": "https://github.com/jason810496/pgmq-sqlalchemy"
    },
    "split_keywords": [
        "pgmq",
        " pgmq",
        " sqlalchemy",
        " sqlalchemy",
        " tembo_pgmq_python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b60a6aedbbc22ea76c38cf6a426d8b74b35070dfcc55ece430bf50b7b88177e2",
                "md5": "91142ec6f71ab379780bc743fbee8e63",
                "sha256": "1f3ddf4c1b5f77874bb2eca1d63ae7a901d2f58a920c42862efc0f2cb3b78af7"
            },
            "downloads": -1,
            "filename": "pgmq_sqlalchemy-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "91142ec6f71ab379780bc743fbee8e63",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 12314,
            "upload_time": "2024-08-03T16:11:29",
            "upload_time_iso_8601": "2024-08-03T16:11:29.081879Z",
            "url": "https://files.pythonhosted.org/packages/b6/0a/6aedbbc22ea76c38cf6a426d8b74b35070dfcc55ece430bf50b7b88177e2/pgmq_sqlalchemy-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "efb37dcc4e06d12105082c7f3ec0390ce70c3c1121aa0d7fa33798b14ed46826",
                "md5": "2c5e98097a78612fb8165278e477d846",
                "sha256": "8ab499aad73f488897e1acc1f39aacbe66554a005e3d86929f9c45589e42105c"
            },
            "downloads": -1,
            "filename": "pgmq_sqlalchemy-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2c5e98097a78612fb8165278e477d846",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 12511,
            "upload_time": "2024-08-03T16:11:30",
            "upload_time_iso_8601": "2024-08-03T16:11:30.379481Z",
            "url": "https://files.pythonhosted.org/packages/ef/b3/7dcc4e06d12105082c7f3ec0390ce70c3c1121aa0d7fa33798b14ed46826/pgmq_sqlalchemy-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-03 16:11:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jason810496",
    "github_project": "pgmq-sqlalchemy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pgmq-sqlalchemy"
}
        
Elapsed time: 0.28834s