Skip to main content

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.

Metadata

Release files for MyPubSub 0.1.1

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

Source distribution (sdist)

Source distribution for MyPubSub 0.1.1
File Size Uploaded
mypubsub-0.1.1.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MyPubSub 0.1.1
File Interpreter ABI Platform
MyPubSub-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / mypubsub-0.1.1.tar.gz

Download URL mypubsub-0.1.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f82c703b1d49b53c2f548ddddde7c1a9abbc071e4ab4736ce8e1d70dc9d5db45
BLAKE2b-256 checksum
How to use checksums
2e479910d774b3886d210bbd5b5eea2b60e87a1e066bba4f9edaf6b274b8e204
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / MyPubSub-0.1.1-py3-none-any.whl

Download URL MyPubSub-0.1.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94a00484278ba7e84894a3d32c3129a43326e26ac6c4296060a7e6fe5feac210
BLAKE2b-256 checksum
How to use checksums
990ecd605972ffb184c2824540488046dfcd79fbbe91a7c96748720deec28187
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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