Skip to main content

Redis IPC

Python application Upload Python Package

A Python library for Redis-based Inter-Process Communication (IPC) with built-in logging capabilities.

Overview

Redis IPC provides a robust framework for implementing inter-process communication using Redis pub/sub mechanisms. It includes utilities for:

  • Redis client management (both sync and async)
  • Channel-based message publishing and subscription
  • Automatic message logging to PostgreSQL databases
  • Verbose logging and debugging support
  • Protocol Buffer message handling

Features

  • Redis Client Management: Base classes for both synchronous and asynchronous Redis operations
  • Channel Management: Easy-to-use channel-based messaging system
  • Message Logging: Automatic logging of all IPC messages to PostgreSQL
  • Protocol Buffer Support: Built-in support for Protocol Buffer message types
  • Verbose Logging: Comprehensive logging and debugging capabilities
  • Database Integration: Seamless integration with PostgreSQL for message persistence

Installation

pip install ryutils

Quick Start

Here's a complete example of how to use the Redis IPC Logger:

import argparse

from ryutils.verbose import Verbose

from config import constants
from database.parse_args import add_postgres_db_args
from ipc.ipc_logger import IpcLogger
from ipc.redis_args import add_redis_args


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description="Run the Redis IPC Logger")

    add_postgres_db_args(parser)
    add_redis_args(parser)

    Verbose.add_arguments(parser, verbose_types=constants.VERBOSE_TYPES)

    return parser.parse_args()


def main() -> None:
    args = parse_args()
    verbose = Verbose(args=args, print_args=True, verbose_types=constants.VERBOSE_TYPES)

    ipc_logger = IpcLogger(verbose=verbose, args=args)
    ipc_logger.subscribe_all()
    ipc_logger.run()


if __name__ == "__main__":
    main()

Usage

1. Setting Up Arguments

The library provides argument parsers for both Redis and PostgreSQL configuration:

from ipc.redis_args import add_redis_args
from database.parse_args import add_postgres_db_args

parser = argparse.ArgumentParser()
add_redis_args(parser)  # Adds Redis host, port, db, user, password, db_name
add_postgres_db_args(parser)  # Adds PostgreSQL connection arguments

2. Creating an IPC Logger

from ipc.ipc_logger import IpcLogger

ipc_logger = IpcLogger(verbose=verbose, args=args)

3. Subscribing to Messages

# Subscribe to all channels
ipc_logger.subscribe_all()

# Start the logger
ipc_logger.run()

Architecture

The library is built around several key components:

  • RedisClientBase: Base class for Redis operations
  • IpcLogger: Main logging class that subscribes to Redis channels
  • RedisReceiver: Handles Redis message reception
  • Channels: Manages channel-based messaging
  • Helpers: Utility functions for common operations

Configuration

Redis Configuration

  • redis_host: Redis server hostname
  • redis_port: Redis server port
  • redis_db: Redis database number
  • redis_user: Redis username (if authentication is enabled)
  • redis_password: Redis password
  • redis_db_name: Redis database name

PostgreSQL Configuration

The library automatically logs all IPC messages to a PostgreSQL database using the LogIpcMessage table.

Message Format

Messages are automatically converted to Protocol Buffer format and include:

  • Message content
  • Channel name
  • Timestamp (UTC)

Development

Requirements

  • Python 3.12+
  • Redis server
  • PostgreSQL database
  • Protocol Buffer support

Running Tests

# Activate virtual environment first
source venv/bin/activate

# Run tests
python -m pytest test/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Release files for ry-redis-bus 2.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ry-redis-bus 2.1.8
File Size Uploaded
ry_redis_bus-2.1.8.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ry-redis-bus 2.1.8
File Interpreter ABI Platform
ry_redis_bus-2.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 30.1 kB

Release files / ry_redis_bus-2.1.8.tar.gz

Download URL ry_redis_bus-2.1.8.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
583e42d25f788e47e7d016e75ef7832cb298058a179dd60625a86167eae93c5c
BLAKE2b-256 checksum
How to use checksums
25a3ec08012b65b6a5d2b6655107565273242c31b6b20bb2c408e2c39fe10bbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / ry_redis_bus-2.1.8-py3-none-any.whl

Download URL ry_redis_bus-2.1.8-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
faac91e102d5e747c9a7bf38a65f48b7e9f2cde7cc14fa3bc9245e5cdc56f450
BLAKE2b-256 checksum
How to use checksums
e166ce94e168bd1ef9c827447c9c38f1beaf6f27b9bd9bbcfd776adce89cd658
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

2.1.8 This release

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page