Skip to main content

Generic Consumer

A flexible Python library for implementing consumer patterns with a focus on payload processing and queue management.

Overview

Generic Consumer provides a framework for creating consumer classes that can process data payloads from various sources. It supports both synchronous and asynchronous processing with features like:

  • Prioritized execution order
  • Payload preprocessing
  • Conditional activation
  • Nested consumer hierarchies
  • Robust error handling
  • Customizable logging

Installation

Using pip

pip install generic-consumer

Quick Start

from generic_consumer import GenericConsumer

class MyConsumer(GenericConsumer):
    # Set the queue this consumer responds to
    @classmethod
    def queue_name(cls):
        return "my_queue"
    
    # Define where to get payloads from
    def get_payloads(self):
        return [1, 2, 3, 4, 5]
    
    # Process a single payload
    def process_one(self, payload):
        print(f"Processing: {payload}")
        
# Run all consumers for a queue
GenericConsumer.start("my_queue")

Key Features

Consumer Configuration

  • queue_name: Define which queue a consumer belongs to
  • priority_number: Set execution priority (lower numbers run first)
  • condition: Determine whether a consumer should run based on runtime conditions
  • enabled: Toggle consumer activation
  • process_empty_payloads: Handle cases where no payloads are available
  • passive: Create consumers that monitor but don't process (useful for logging)

Processing Pipeline

  1. get_payloads: Retrieve data to be processed
  2. payload_preprocessors: Transform payloads before processing
  3. process: Handle batch processing of all payloads
  4. process_one: Process individual payloads

Utility Methods

  • start_all/start: Run all consumers for a given queue
  • print_available_consumers: Display all registered consumers and their configurations
  • run: Execute a specific consumer
  • run_all: Execute all consumers

Advanced Usage

Passive Consumers

Use PassiveConsumer for monitoring or logging without modifying data:

from generic_consumer import PassiveConsumer

class LoggingConsumer(PassiveConsumer):
    @classmethod
    def queue_name(cls):
        return "my_queue"
    
    def process(self, payloads):
        print(f"Observed {len(payloads)} items")

Metadata

Release files for generic-consumer 0.20.2

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

Source distribution (sdist)

Source distribution for generic-consumer 0.20.2
File Size Uploaded Provenance Actions
generic_consumer-0.20.2.tar.gz 7.2 kB Without provenance Details for generic_consumer-0.20.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for generic-consumer 0.20.2
File Interpreter ABI Platform Actions
generic_consumer-0.20.2-py3-none-any.whl Python 3 none any Details for generic_consumer-0.20.2-py3-none-any.whl

Total release size: 15.8 kB

Release files / generic_consumer-0.20.2.tar.gz

Download URL generic_consumer-0.20.2.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3c0d777caab9865381f5093a7422b9cf231789690e00eb8098ff3b2369b2a625
BLAKE2b-256 checksum
How to use checksums
6811af9cea69b75c0ba7afc63e38d6ba9b83ba54d11d7f7f35d23f4e7e0551e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-19-generic

Release files / generic_consumer-0.20.2-py3-none-any.whl

Download URL generic_consumer-0.20.2-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee7a1e7fa2f95c455d23722479ee279901d63922cdd17c6db82de7688292ad30
BLAKE2b-256 checksum
How to use checksums
90acf82e94aca501c6a193cb13215e38c519e11e5782d7999de0d9aab2dc9039
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-19-generic

Security for generic-consumer 0.20.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.20.2 This release

2 release files No provenance

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