Skip to main content

A simple async event handling library using PostgreSQL notifications.

Project description

pg-async-events

A simple asynchronous event handling library using PostgreSQL notifications. This library allows you to subscribe to and publish events using PostgreSQL's LISTEN/NOTIFY mechanism in an asynchronous environment.

This is useful in generative AI applications or for situations where other pub/sub systems are overkill.

Features

  • Asynchronous Event Handling: Leverage asyncio and asyncpg to handle events without blocking your main application logic.
  • PostgreSQL Notifications: Seamlessly integrates with PostgreSQL's LISTEN/NOTIFY to provide real-time event notifications.
  • Simple API: Easy-to-use API for subscribing to channels and notifying events.

Installation

You can install the package directly from PyPI:

pip install pg_async_events

Usage

Quart

import pg_async_events as events

# Add your postgres credentials from the env
db_config = {
    "user": POSTGRES_USER,
    "password": POSTGRES_PASSWORD,
    "host": POSTGRES_HOST,
    "port": POSTGRES_PORT,
    "max_connections": 1,
}

@app.before_serving
async def setup():
    await events.initialize(db_config)

Notifications

import pg_async_events as events

async def listen_to_events():
    async for message in events.subscribe('your_channel'):
        print('Received:', message)

async def publish_event():
    payload = {'key': 'value'}
    await events.notify('your_channel', payload)

Requirements

  • Python 3.8+
  • PostgreSQL 9.0+ (with support for LISTEN/NOTIFY)
  • asyncpg library

Author

Built by 255labs.xyz, the AI product and consulting startup helping people adapt to the AI age with consulting, product, and open-source development.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss the changes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Thanks

  • asyncpg for providing the asynchronous PostgreSQL driver.
  • PostgreSQL community for their robust database and features like LISTEN/NOTIFY.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pg_async_events-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

pg_async_events-0.1.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pg_async_events-0.1.1.tar.gz.

File metadata

  • Download URL: pg_async_events-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for pg_async_events-0.1.1.tar.gz
Algorithm Hash digest
SHA256 92ac2112274626bc81837174a7a0cdcc4b3740f9b5302091f9907de8928c1b9d
MD5 59fe23df95988142e9f9bf6bd1d743d8
BLAKE2b-256 ebf1c022516e16e455f6981a7e92ba32a22b2a07990eb95c501a461a0454400c

See more details on using hashes here.

File details

Details for the file pg_async_events-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pg_async_events-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f6a7d194fc4c32197ab04efb50ee4aa83e6794d434592aa136f5d74304b3b7e
MD5 beee709572c36b6467c5f809b417b0c7
BLAKE2b-256 e31f2c6edeb525975f19de7e99a72a717ed2e67feac1db9a882115a660f176a2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page