Skip to main content

A basic Python library for a Singleton Pub Sub System

Project description

MyPubSub

MyPubSub is a Python library implementing the publish-subscribe pattern. It provides a simple and effective way to manage event-driven communication between different parts of an application. This project also demonstrates the use of the Singleton pattern to ensure that only one instance of the PubSub system exists.

Features

  • Publish-Subscribe Pattern: Facilitate event-based communication where publishers send messages and subscribers receive them.
  • Singleton Pattern: Ensures only a single instance of the PubSub system exists throughout the application.
  • Flexible Event Management: Allows for dynamic subscription and unsubscription of events.

Installation

To use the MyPubSub library, you need to install the required dependencies. You can install them using pip:

pip install .

Dependencies

  • Python 3.8 or higher
  • pylint (for code quality checks)
  • pytest (for testing)

Usage

Here’s a basic example of using the MyPubSub class:

from mypubsub import MyPubSub

# Get the singleton instance of MyPubSub
pubsub = MyPubSub.get_instance()

# Define a callback function for subscribers
def handle_message(message):
    print(f"Received message: {message}")

# Subscribe to an event
pubsub.subscribe('event_topic', handle_message)

# Publish a message to the event
pubsub.publish('event_topic', 'Hello, World!')

# Unsubscribe from the event
pubsub.unsubscribe('event_topic', handle_message)

# Reset the singleton instance (useful for testing)
MyPubSub.reset_instance()

Testing

To run tests, ensure pytest is installed:

pip install pytest

Then execute the tests with:

pytest

Contributing

Contributions are welcome! To contribute, fork the repository, create a new branch, and submit a pull request. Ensure that your changes include appropriate tests.

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

mypubsub-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

MyPubSub-0.1.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mypubsub-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f82c703b1d49b53c2f548ddddde7c1a9abbc071e4ab4736ce8e1d70dc9d5db45
MD5 0fd96ecbdabad62b69812043be27c981
BLAKE2b-256 2e479910d774b3886d210bbd5b5eea2b60e87a1e066bba4f9edaf6b274b8e204

See more details on using hashes here.

File details

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

File metadata

  • Download URL: MyPubSub-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for MyPubSub-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94a00484278ba7e84894a3d32c3129a43326e26ac6c4296060a7e6fe5feac210
MD5 70ac6f3ac46bbd46f0ef940b1d634d62
BLAKE2b-256 990ecd605972ffb184c2824540488046dfcd79fbbe91a7c96748720deec28187

See more details on using hashes here.

Supported by

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